我通过 jQuery 调用 AJAX 到同一个域上的脚本,一切都成功了,数据在数据库中等等,但 AJAX 仍然给我返回错误。我试图用 JSON 输出,没有帮助。昨天还好好的,现在不行了。
$.ajax({
url: "http://www.thirst4water.org/api/?request=sign_petition"+query_string,
success: function(data){ // Ajax successfull
alert('Request successful and id is'+data);
// Hide loader
$('.join-us .loader').hide();
// If return is numeric we have id, if not we have error
if (isNumber(data)){
window.userId = data; // Save gobally new user id
$('.join-us').fadeOut(); // Hide the Signing form
// If we have userPic that means user came from facebook, and can skip uploading of picture
if(window.userPic){
// Store avatar from facebook
tomUploadAvatar(window.userPic);
// Switch the steps
$('#step2').fadeOut('normal',function(){
$('#step3').fadeIn(); // Let's see the final step
});
// And re-load the dragon
tomReloadDragonPerson(window.userId);
} else {
$('.join-us').fadeOut('normal',function(){ // Hide the Signing form
$('#step2').fadeIn(); // In case we didnt come from facebook we show uploading form
});
}
} else {
$('.join-us .actions').html(data);
}
},
error: function(value1,value2,value3){
alert(JSON.stringify(value1)+JSON.stringify(value2)+JSON.stringify(value3));
},
});
return false;
});
PHP 脚本很好,如果我只是打开地址一切正常。
最佳答案
尝试改变这个
url: "http://www.thirst4water.org/api/?request=sign_petition"+query_string,
success: function(data){ // Ajax successfull
对此
url: "http://www.thirst4water.org/api/?request=sign_petition"+query_string,
dataType: "json",
success: function(data){ // Ajax successfull
关于javascript - 当一切正常时,带有 jQuery 的 Ajax 返回错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9406545/