3

由于某种原因,下面的 ajax 代码存在解析错误。我怎么能找出它是什么,和/或有人能看出什么问题吗?

$('#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);
                    }
                }
            });
        }
4

2 回答 2

1

此 JavaScript 代码中没有解析错误。

请发布“index.php”的响应和您收到的错误消息。

查看响应数据。在浏览器中打开 index.php,按 F12 并将其插入控制台:

       $.ajax({
            type: "POST",
            url: "index.php",
            //dataType: "json",
            data: { json: order },
            success: function(data) {
               console.log(data);
            }
        });
于 2012-10-23T15:01:37.777 回答
1

data: { json: order } ...格式不正确...

于 2012-10-23T15:08:12.923 回答