Ajax Http Error Codes
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss an ajax http error occurred http result code 200 the workings and policies of this site About Us Learn more ajax error response code about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow ajax http error 500 Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each
An Ajax Http Error Occurred Drupal
other. Join them; it only takes a minute: Sign up jQuery AJAX Error Handling (HTTP Status Codes) up vote 20 down vote favorite 3 We have an API which uses proper HTTP status codes for errors, and responds with JSON-encoded responses and appropriate Content-Type header. My situation is that jQuery.ajax() triggers the error callback when it encounters an an ajax http error occurred drupal 7 HTTP error status, and not the success callback, so even when we have an intelligible JSON response, we have to resort to something like this: $.ajax({ // ... success: function(response) { if (response.success) { console.log('Success!'); console.log(response.data); } else { console.log('Failure!'); console.log(response.error); } }, error: function(xhr, status, text) { var response = $.parseJSON(xhr.responseText); console.log('Failure!'); if (response) { console.log(response.error); } else { // This would mean an invalid response from the server - maybe the site went down or whatever... } } }); Is there a better paradigm than doing identical error handling in two spots in each jQuery.ajax() call? It's not very DRY, and I'm sure I've just missed something somewhere on good error handling practices in these cases. jquery ajax error-handling share|improve this question asked Oct 4 '12 at 19:44 drrcknlsn 11.4k73879 I'm assuming by HTTP Status code, you mean you are sending back 501 as the HTTP status code on error. Why would you do that if you are properly handling the error on the server side? –Lawrence
Friendly Test » Keyword Density » Keyword Generator » MozRank Checker » Alexa Ranking » PageRank Check » Twitter Card Generator » Facebook Open Graph » Social Media Shares » Keyword Analyzer Online Tools » QR Code Generator » ajax error response body IP Geolocation » My IP Address » Server Headers Check » Share Link Generator
Ajax Response Error Handling
» Minify JavaScript » Minify CSS » HTML Encoder » URL Encoder HTTP Status and Error Codes Explained The following
Http Error Codes Cheat Sheet
is a list of HTTP response status codes and standard associated phrases, intended to give a short textual description of the status. 1xx Informational 2xx Success 3xx Redirection 4xx Client Error 5xx Server Error 1xx http://stackoverflow.com/questions/12734714/jquery-ajax-error-handling-http-status-codes InformationalRequest received, continuing process. top Code Status Explanation 100 Continue The request has been completed and the rest of the process can continue. 101 Switching Protocols When requesting a page, a browser might receive a statis code of 101, followed by an "Upgrade" header showing that the server is changing to a different version of HTTP. 2xx SuccessThe action was successfully received, understood, and accepted. top Code Status Explanation http://www.seocentro.com/articles/apache/http-status-codes.html 200 OK Standard response for HTTP successful requests. 201 Created When new pages are created by posted form data or by a CGI process, this is confirmation that it worked. 202 Accepted The client's request was accepted, though not yet processed. 203 Non-Authorative Information The information contained in the entity header is not from the original site, but from a third party server. 204 No Content If you click a link which has no target URL, this response is elicited by the server. It's silent and doesn't warn the user about anything. 205 Reset Content This allows the server to reset any content returned by a CGI. 206 Partial Content The requested file wasn't downloaded entirely. This is returned when the user presses the stop button before a page is loaded, for example. 3xx RedirectionThe client must take additional action to complete the request. top Code Status Explanation 300 Multiple Choices The requested address refers to more than one file. Depending on how the server is configured, you get an error or a choice of which page you want. 301 Moved Permanently If the server is set up properly it will automatically redirect the reader to the new location of the file. 302 Moved Temp
Andrew Abbott , and Chuck Leverette Handling AJAX Errors With jQuery By Ben Nadel on November 7, 2008 Tags: AJAX, Javascript / DHTML jQuery is the most awesome http://www.bennadel.com/blog/1392-handling-ajax-errors-with-jquery.htm javascript library that exists. Every day, I'm finding new ways to leverage it and shorter, more efficient ways to get things done. But, while most things are easy to do, the solution is not always immediately evident. One of the things that took me a good while to figure out was how to gracefully handle AJAX errors. Anyone who's worked with JSON requests and http error other AJAX calls knows that sometimes, that stuff just fails silently; you know something went wrong, but no errors were thrown. If it wasn't for FireBug showing us 404 or 500 style errors, there'd be no evidence at all of these fails.I've come up with a way to centralize my AJAX calls in a way that seemlessly handles all errors that occur either from the ajax http error request connection or the JSON processing (ie. poorly formed JSON that cannot be converted back into Javascript data types). I'm not sure if this is the best of all ways, but I'm liking it. The whole concept rests on the fact that all of my system API (AJAX) calls return a uniform response with the following structure:{SUCCESS: true,DATA: "",ERRORS: []}The Success property flags the request as having executed properly and returned the expected data. The Data property can be anything it needs to be. The Errors property is an array of any errors that need to be reported. It is only by requiring that all AJAX requests expect this that I can easily handle all errors.In production, the following code would probably be part of some other object or integrated into the Javascript framework in a different way, but for this demo, I'm going to break out my AJAX request pipeline into its own class:// Create an object to handle our AJAX.function AJAX(){var objSelf = this;// This struct will cache the current XmlHTTP requests// so that we can reference them if a call fails.this.CurrentRequests = {};}// This handles the JSON request.