10

There is an undefined error due to Ajax request in jQuery. But it works locally. Error referencing in jquery1.3.2.js @ 3633 line

xhr.send(s.data);

My code is:

$.ajax({
    type: "POST",
    url: 'index.php',
    data: "action=showpath&type=images&path=&default=1",
    cache: false,
    dataType: "html",
    success: function (data) {
        $('#addr').html(data);
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
    }
});

alerts in code shows me (0, 'undefined');

What I am doing wrong?

2 Answers 2

23

This could be happening if your ajax request is getting canceled before it completes. jQuery throws the error event when the user navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser. You can detect these types of errors by by implementing an error handler for the ajax call, and inspecting the xmlHttpRequest object:

$.ajax({
    /* ajax options omitted */
    error: function (xmlHttpRequest, textStatus, errorThrown) {
         if(xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0) 
              return;  // it's not really an error
         else
              // Do normal error handling
});
Sign up to request clarification or add additional context in comments.

Comments

0

Couldn't tell ya offhand, but it is probably something on the server-side in index.php. Best way to tell is to look at the raw response using a http debugger. The Firebug firefox extension has a pretty good one, and fidder2 is a beefy option.

2 Comments

I have tested it with firebug. There is erroneous response displyed, but it's own status is 200 - OK. Ajax request returns ajaxError without explanation.
I have found same problem description at mail-archive.com/[email protected]/msg65106.html But still no solution.

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.