当一切正常时,带有jQuery的Ajax会返回错误

时间:2012-02-23 03:02:37

标签: javascript jquery ajax

我通过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脚本没问题,如果我只打开地址一切正常。

1 个答案:

答案 0 :(得分:1)

尝试更改此

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