Basit
Basit

Reputation: 17184

jquery find if its json or xml

i want to know if the response is the json or xml, how can i find that out using jquery?

my current code is following, but its giving error, if response is json.

var is_xml = ($('status_code', XMLHttpRequest.responseText)) ? true : false;

error is:

Selector expected.

Expected ',' or '{' but found '"}}"'.

Upvotes: 1

Views: 1318

Answers (2)

Ken Browning
Ken Browning

Reputation: 29091

According to the documentation, the third parameter to an ajaxError callback is the options object which was passed into the call to jQuery.ajax. You can query the dataType value of that object to determine if the call was expected to return json or xml. Of course, this assumes you set the dataType option appropriately to begin with.

Upvotes: 2

meder omuraliev
meder omuraliev

Reputation: 186552

Why is the return format not consistent? IMO you should know exactly what should come back before even requesting the page.

Upvotes: 1

Related Questions