Error while displaying $ .post using $ .ajaxError

I would like to catch the ERR_EMPTY_RESPONSE error when I do $. post .

My jquery code $ .post:

        $.post( "parseRequest", { request: "myFile.xml" }, function( data ) {
            //do something with json data
        }, "json");

      

Sometimes, if the file does not exist, for example, the server sends an empty response. I will get this on the client side:

POST http://localhost:8081/parseRequest net::ERR_EMPTY_RESPONSE 

      

Is there a way to catch this?

I tried using .ajaxError () but I am not using it correctly ... this is what I tried:

        $.post( "parseRequest", { request: "myFile.xml" }, function( data ) {
            //do something with json data
        }, "json").ajaxError(function() {
            console.log( "** Triggered ajaxError handler." );
        });

      

But I am getting 'function undefined' error when I try to do this.

I am using jquery 1.11.1

Relevant pages:

  • $. post: http://api.jquery.com/jquery.post/
  • $. ajaxError: http://api.jquery.com/ajaxError/

Any help? Thank!

+3
javascript jquery


source to share


No one has answered this question yet

Check out similar questions:

2268
Why is my JavaScript code getting the error "No Access-Control-Allow-Origin header" on the requested resource ", but not Postman?
1379
JavaScript submit request, how to submit a form
390
How can I submit FormData objects using Ajax requests in jQuery?
237
JavaScript / jQuery to upload file via POST with JSON data
118
jQuery sends valid json to request body
71
What should the JSON service return on failure / error
1
Checking for jQuery $ .post () error due to lost connection
1
jQuery.post () data not "post"
0
Error sending jquery error to server?
0
How to get JSON object in jQuery ajaxError?



All Articles
Loading...
X
Show
Funny
Dev
Pics