2012-10-23 143 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