ResponseType in $ .ajax

$.ajax({
   type: "POST",
   url: "bla",
   xhrFields: { responseType: "document" },
   data: {},
   success: function(arg,arg2,request){
      console.log(request.responseXML)
   }
})

      

Why is it printing 'undefined'? How can I fix this?

+3
jquery xml ajax jqxhr


source to share


1 answer


Are you expecting JSON to return? What happens when you try:

$.ajax({
  type: "POST",
  url: "bla",
  dataType: 'xml',
}).done(function (response) {
   console.log(response);
});

      

If you look at the jQuery documentation , they describe how:



The jQuery XMLHttpRequest (jqXHR) object returned by $ .ajax () from jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains the responseText and responseXML properties as well as the getResponseHeader () method.

Therefore, the response variable contains what you need. To see its structure, execute console.log()

and go to the Console tab in Developer Tools (Chrome) or Firebug (Firefox).

+4


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics