2012-02-23 25 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