开发者

Jquery ajax inside function

开发者 https://www.devze.com 2023-03-17 16:58 出处:网络
$(function () { $(\"#rv-title\").click(function(event) { $(\"#rv-content\").toggle(); $.ajax({ url: \'index.php?route=check\',
$(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();
      }
   });
});

Where my ajax function is, is that the right place to put it?

Thanks


try this

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

    });

or

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

my_ajax();

});

function my_ajax(){

//ajax call

}


You can pass the function as a parameter to your toggle call. e.g.

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

see: http://api.jquery.com/toggle/

0

精彩评论

暂无评论...
验证码 换一张
取 消