我的 AJAX 调用有问题。我有一个带有“showuserinfo”类按钮的列表,当我点击 showuserinfo 并返回并再次点击时,AJAX 调用不止一次。如果我点击 showuserinfo,返回并再次点击,AJAX 调用会工作两次。如果我重复执行此操作,AJAX 调用也会重复运行。这是我的代码:
$('.showuserinfo').live('tap', function(event){
$.mobile.loading('show');
var user_id = $(this).children().find('a').attr('id');
//$('#showprofile').page('destroy').page();
$('#showprofileImage img').remove();
$('#showprofileContent div').remove();
$( document ).delegate("#showprofile", "pagebeforeshow", function() {
$.ajax({
type: "POST",
url: "http://fitness.desigyn.com/func/phonegapApi.php",
data: { operation: "getSpecificProfile", requested: user_id ,username: 'kurekcifuat', password: '123456' },
async : false,
cache : false,
}).done(function( msg ) {
if(msg == "fail")
{
alert('error');
}
else{
var obj = $.parseJSON(msg);
alert(msg); // Debugging and that code works more than once
$('#showprofileImage img').remove();
$('#showprofileContent div').remove();
$('#showprofileImage').append('<img class="otheruserpic" style="height:120px !important; width:120px !important;" src="' + obj["0"].picture + '"/>');
$('#showprofileContent').append('<div class="otheruserinfo"><b>Username: </b><span>' + obj["0"].username + '</span></div><div><b>Name: </b><span>' + obj["0"].name + '</span></div><div><b>Age: </b><span>' + obj["0"].age + '</span></div><div><b>Gender: </b><span>' + obj["0"].gender + '</span></div>');
}
});
$.mobile.loading('hide');
});
});
有什么建议么?干杯。