2011-07-07 67 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

在您看来,哪一个更有效? –

+0

第二个,因为你可以多次调用my_ajax()函数。因为。再次写同样的想法是浪费时间。 – Gowri

1

你也可以传递函数作为参数传递给您的通话切换。 例如

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

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