jQuery XMLHTTPRequest错误0

I have a CSS modal that pops up where a user interacts with some HTML elements that populate a hidden input, they then press a button which triggers the POST to my handler.

It had been working perfectly fine then all of a sudden I started getting XMLHTTPRequest error 0 every time the submit button had been pressed.

All I read has been saying that it is because the request is being cancelled, or because of cross domain calls. The page doesn't refresh, it's a p tag for which the click function is called on so it can't be navigating away from that page, and the

is not in a form so it's not submitting anything. The POST is simply pointed to ./ajax/dothis/ (which by dothis is the functions name that gets rewritten to PHP).

The handler file is a PHP file that does some logic and spits out JSON (for which I've added the application/json header).

Any help would be much appreciated. The sudden occurrence of this is really frustrating.

Thanks.

So you are using AJAX in "POST" mode to send the information to your handler page. Then after you launch the request the request errors out?

It sounds like you are building your own AJAX calls, and not using some js library like jQuery.

This is definitely the time to start using "debug print statements" to figure out where exactly breakdown is occurring.

Inside of your AJAX function that POSTS the data back to the form, try using "alert('some debug message');" to print out your input values to the screen so you can see what the actual value is that js is retrieving from your page.

Also you can include this in your code:

http.onreadystatechange = function() 
{
    //Call a function when the state changes.

    // Ready State codes and their associated meanings
    //0 Uninitialized - open() has not been called yet.
    //1 Loading - send() has not been called yet.
    //2 Loaded - send() has been called, headers and status are available.
    //3 Interactive - Downloading, responseText holds the partial data.
    //4 Completed - Finished with all operations.

    // There are also the status codes to work with too, to help you deduce errors.
    //200   Successfully completed
    //Every other status code is an error message of some type that will help you
    //deduce what is going wrong.

    if(http.readyState == 0)
    {
        alert("Uninitialized, Open Not Called yet");
    }
    if(http.readyState == 1)
    {
        alert("Loading, Send Not Called yet")
    } 
    if(http.readyState == 2)
    {
        alert("Loaded, Send called, headers and status available");
    }
    if(http.readyState == 3)
    {
        alert("Downloading");
    }
if(http.readyState == 4 && http.status == 200) {
    alert(http.responseText);
}
    else if(http.readyState == 4 && http.status != 200)
    {
         alert("Request completed with this error number: " + http.status);
    }
}

Here is a link to the w3.org documentation on AJAX infrastructure, its pretty technical, but very comprehensive, as it is the standard.

w3.org Ajax requests

So to sum up, check all of your input dynamically, and make sure that Javascript is extracting your values correctly, then check the AJAX state and status to make sure that it received it properly, then proceed to attempting debugging methods on your handler script. This obviously is not an answer to your problem, but will hopefully get you closer to solving it. Feel free to post your debugging results back to this thread so myself or others will be able to help you out.

Kind Regards,

H