开发者

jquery find if its json or xml

开发者 https://www.devze.com 2022-12-08 01:36 出处:网络
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.

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 开发者_JS百科',' or '{' but found '"}}"'.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号