Jquery ajax inside function
$(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/
精彩评论