3

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);
                    }
                }
            });
        }
11
  • 1
    parseing error in this js code, or in the resulting json text on the server? Commented Oct 23, 2012 at 14:59
  • have you tried removing the leading / on index.php? Commented Oct 23, 2012 at 15:00
  • 4
    Don't tell us what the exact problem is. It would take away all the fun of guessing! Everybody knows engineers love guessing. Commented Oct 23, 2012 at 15:00
  • can you debug-output your order variable? Commented Oct 23, 2012 at 15:00
  • 1
    ok, so the JSON from index.php is wrong. That means the code you posted has nothing to do with the problem. Can you post the JSON response or index.php? What browser do you use? Commented Oct 23, 2012 at 15:14

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

a little more explanation!
1

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);
            }
        });

2 Comments

What is the order here near data : {json : order}
@Sabarish That is from the question var order = [];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.