2011-07-07 9 views
0
$(function() { 
    $("#rv-title").click(function(event) { 
    $("#rv-content").toggle(); 



    $.ajax({ 
     url: 'index.php?route=check', 
     dataType: 'json', 
     success: function(json) { 
      if (json['output']) { 
       $('#cart .content').html(json['output']); 
      } 
     } 
    }); 


    event.stopPropagation(); 
}); 


$(document).click(function(event) { 
    var a = $(event.target).andSelf().parents("#rv-content"); 
    if (a.length == 0 && $("#rv-content").is(":visible")) { 
     $("#rv-content").toggle(); 
     } 
    }); 
}); 

私のajax関数は、それを置くための正しい場所ですか?関数内のJquery ajax

おかげ

答えて

2

はあなたのトグルコールへのパラメータとして関数を渡すことができ、この

$("#rv-content").toggle(function(){ 
    //your ajax call 

    }); 

または

$("#rv-content").toggle(function(){ 

my_ajax(); 

}); 

function my_ajax(){ 

//ajax call 

} 
+0

、より効率的である1? 2回目は、my_ajax()関数を複数回呼び出すことができるため、 –

+0

です。なぜなら。同じことをもう一度考えることは時間の無駄です。 – Gowri

1

を試してみてください。例:

$("#rv-content").toggle(function(){ /* put your code here... */ }); 

を参照してください:あなたの意見では http://api.jquery.com/toggle/

関連する問題