Jquery - Read HTTP response from a promise/deferred Ajax response

kitimenpolku

I'm new to jquery promises and deferred objects. I'm trying to get or analyze the response of a POST/PUT/DELETE ajax request. I'm looking to be able to read the HTTP status code (200, 204, ...).

When using $.when and the deferred objects in this way:

$.when($.ajax(request)).then(callback_function(response))

It is possible to analyze the HTTP status code? The response vble itself is empty, since there is no data in the response. If it is not possible, Would the solution be to use done() or fail() functions? What if it is important to recognize the HTTP status code to act over it?

user1765062

Check jQuery documentation http://api.jquery.com/jQuery.ajax/ and search for "The jqXHR Object" there you have the solution.

The jqXHR objects returned by $.ajax() as of jQuery 1.5 implement the Promise interface, giving them all the properties, methods, and behavior of a Promise (see Deferred object for more information). These methods take one or more function arguments that are called when the $.ajax() request terminates. This allows you to assign multiple callbacks on a single request, and even to assign callbacks after the request may have completed. (If the request is already complete, the callback is fired immediately.) Available Promise methods of the jqXHR object include:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery read array from ajax response

From Dev

Get Http Status Code from an ajax response with jquery

From Dev

AngularJS - Cannot read response headers from $http

From Dev

Handling exception in Jquery AJAX response from Servlet

From Dev

Displaying data from an Ajax response with Jquery

From Dev

AJAX/Jquery - Get response from php file

From Dev

jQuery - Remove some elements from AJAX response

From Dev

Jquery - Can't remove() from AJAx response

From Dev

Call function in jQuery from AJAX response

From Dev

jQuery - access multidimesional array from ajax response

From Dev

Create Jquery array from ajax response

From Dev

jQuery manipulating table rows from ajax response

From Dev

jQuery: Post data from ajax response

From Dev

jQuery get response from ajax function

From Dev

Handling exception in Jquery AJAX response from Servlet

From Dev

jQuery AJAX gets no response from PHP

From Dev

jquery.ajax - how to remove http headers from .net web service response

From Dev

jQuery ajax cache response

From Dev

jQuery - response of ajax

From Dev

Toggling an AJAX Response in jQuery

From Dev

jQuery - response of ajax

From Dev

AJAX response not appending with JQuery

From Dev

Read HTTP response header and body from one HTTP request in java

From Dev

catch a 401 Unauthorized http response using jquery ajax

From Dev

How to read AJAX response variable?

From Dev

How to read JSON error response from $http if responseType is arraybuffer

From Dev

Access response from jQuery.get() or jQuery.ajax()

From Dev

How to read a json response from a akka-http response entity using json4s

From Dev

HTTP request / response with response from a different server

Related Related

HotTag

Archive