2012-10-23 138 views
0

由於某種原因,下面的ajax代碼存在解析錯誤。我怎麼能找出它是什麼,和/或有人可以看到什麼是錯的?請求的JSON解析失敗

$('#listElements').sortable({ 
     //revert: true, 
     update: function(event, ui) { 

      var order = []; 
      $('.listObject li').each(function (e) { 
       order.push($(this).attr('id')); 
      }); 
      $.ajax({ 
       type: "POST", 
       url: "index.php?", 
       dataType: "json", 
       data: { json: order },     error: function(jqXHR, exception) { 
        if (jqXHR.status === 0) { 
         alert('Not connect.\n Verify Network.'); 
        } else if (jqXHR.status == 404) { 
         alert('Requested page not found. [404]'); 
        } else if (jqXHR.status == 500) { 
         alert('Internal Server Error [500].'); 
        } else if (exception === 'parsererror') { 
         alert('Requested JSON parse failed.'); 
        } else if (exception === 'timeout') { 
         alert('Time out error.'); 
        } else if (exception === 'abort') { 
         alert('Ajax request aborted.'); 
        } else { 
         alert('Uncaught Error.\n' + jqXHR.responseText); 
        } 
       } 
      }); 
     } 
+0

怎樣的錯誤說? –

+1

解析錯誤在這個JS代碼,或在服務器上的結果JSON文本? –

+0

你有沒有嘗試刪除前導index.php? –

回答

0

數據:{JSON:爲了} ...它的格式不正確......

+0

好的,它應該如何格式化? – holyredbeard

+0

我認爲這可能會有所幫助:http://stackoverflow.com/questions/6085649/ajax-multiple-data – sataniccrow

0

此JavaScript代碼沒有解析錯誤。

請發佈「index.php」的回覆和你得到的錯誤信息。

查看響應數據。在瀏覽器中按F12打開index.php文件並插入到這個控制檯:

 $.ajax({ 
      type: "POST", 
      url: "index.php", 
      //dataType: "json", 
      data: { json: order }, 
      success: function(data) { 
       console.log(data); 
      } 
     }); 
+0

這裏附近的數據命令是什麼:{json:order} – Sabarish

+0

@Sabarish這是來自'var order = [];' – PiTheNumber

+0

這個問題我得到了謝謝@PiTheNumber – Sabarish