2012-02-23 34 views
3

我在这里变得疯狂。 我正在通过jquery调用同一个域上的脚本,一切都成功,数据在数据库等,但Ajax仍然给我回错误。我试图用JSON做输出,没有帮助。这是昨天刚刚做工精细,但它不是现在的工作...Ajax与jQuery在一切正常时都会返回错误

$.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脚本是好的,如果我只是打开地址一切工作正常。有人可以帮助我吗?这是一种迫切

+0

顺便说一句,这是我所得到的(错误):{ “readyState的” 0 “responseText的”: “” ,“status”:0,“statusText”:“error”},“error”,“” – Tom 2012-02-23 03:03:41

+0

php脚本是否有正确的标题?例如'header('Content-type:application/json');' – aletzo 2012-02-23 03:05:32

+0

是否需要json?我会尝试只是为了测试设置页眉 – Tom 2012-02-23 03:08:07

回答

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 
+0

好像它是跨域问题,如果我删除的域名,并保持刚/ API/...它的工作,反正他们决定,他们希望它再次另一种方式,所以这是不相关anyore。但谢谢你的帮助! – Tom 2012-02-23 15:55:27

+0

我明白了。别客气! – 2012-02-24 09:22:18