2013-04-15 77 views
0

我有以下的碼位,我特林運行

$.ajax({ 
     cache: false, 
     url: './animationPlay.php', 
     data: 'animation='+text, 
     type: 'POST', 
     datatype: 'text', 
     success: function(data) { alert("succsess") }, 
     error: function(ts) { alert('error:'+ts.responseText) } 
    }); 

我見過how to catch ajax query post error?jQuery $.get or $.post to catch page load error (eg. 404),但它不工作對我code.It被簡單地設置「錯誤」。我如何獲得有關錯誤的更多細節?

在此先感謝。

編輯: 我試過

error: function(xhr, textStatus, error){ 
    console.log(xhr.statusText); 
    console.log(textStatus); 
    console.log(error); 
} 

我有錯誤,錯誤,在控制檯一個空字符串。這是什麼意思?

+0

不顯示任何空白提示 – Apb

+0

@Baadshah - 他在代碼中顯示他正試圖捕獲錯誤,但'ts.responseText'不會返回任何內容 – ChrisW

+3

嘗試從url中刪除'.'。所以它是'url:'/ animationPlay.php'' –

回答

-1

嘗試發送後數據爲對象...

$.ajax({ 
    cache: false, 
    url: './animationPlay.php', 
    data: { 
     animation: text 
    }, 
    type: 'POST', 
    success: function(data) { alert("succsess") }, 
    error: function(ts) { alert('error:'+ts.responseText) } 
}); 
+0

不會有所作爲,對象字面量將被轉換爲相同的查詢字符串。 –

+1

@AnthonyGrist:這不是真的,因爲這是一個帖子,而不是一個get? –

+0

我是jquery中的新成員。我有價值的文字在點擊時發生變化。可以通過這種方式傳遞文本的價值嗎? – Apb

-1
$.ajax({ 
     cache: false, 
     url: './animationPlay.php', 
     data: 'animation='+text, 
     type: 'POST', 
     dataType: 'text', 
     success: function(data) { alert("succsess") }, 
     error: function(ts) { alert('error:'+ts.responseText) } 
     contentType:'SET THE CONTENT TYPE' 
    }); 

檢查的URL

+0

仍然沒有顯示任何空白警報 – Apb

0

的存在性試試這個::

$.ajax({ 
     cache: false, 
     url: './animationPlay.php', 
     data: { 
      animation: text 
     }, 
     type: 'POST', 
     datatype: 'text', 
     success: function(data) { alert("succsess") }, 
     error: function(XMLHttpRequest, textStatus, errorThrown){ 
      alert('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText); 
     } 
+0

警報:狀態:0,狀態文本:錯誤 – Apb

+1

這可能有助於您的0狀態代碼問題:http://stackoverflow.com/questions/2000609/jquery-ajax-status-code-0 – jjenzz

-1

試試這個:

$.ajax({ 
     cache: false, 
     url: 'animationPlay.php', 
     data: text, 
     type: 'POST', 
     dataType: 'text',  //<== see, in your question's code you have small 't' 
     success: function(data) { alert("succsess") }, 
     error: function(){ 
      alert('error'); 
     } 
+0

警報錯誤 沒有任何區別 – Apb