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

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

hohner
  • 11,498
  • 8
  • 49
  • 84
Luaox
  • 167
  • 1
  • 3
  • 13
  • As well as the answer below I must point out that the URL `bla` must tell the browser the content type is application/json. – Popnoodles Jan 19 '13 at 17:30

1 Answers1

4

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

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

If you look at jQuery's documentation, they outline how:

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

The response variable therefore contains what you need. To see its structure, do a console.log() and go to the 'Console' tab in your Developer Tools (Chrome) or Firebug (Firefox).

hohner
  • 11,498
  • 8
  • 49
  • 84