Requested JSON parse failed

2019-05-25 13:04发布

By some reason there's a parsing error with the ajax code below. How could I find out what it is, and/or can someone see what's wrong?

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

2条回答
The star\"
2楼-- · 2019-05-25 13:37

data: { json: order } ... it's not well formatted...

查看更多
走好不送
3楼-- · 2019-05-25 13:37

There is no parsing error in this JavaScript code.

Please post the response of "index.php" and the error message you got.

Have a look at the response data. Open index.php in the browser, press F12 and insert this into the console:

       $.ajax({
            type: "POST",
            url: "index.php",
            //dataType: "json",
            data: { json: order },
            success: function(data) {
               console.log(data);
            }
        });
查看更多
登录 后发表回答