0

Ajax returned data/datatypes

Hi,

I have a few questions regarding the datatypes returned from an ajax request and the manipulation of said data.

My app is requesting information from a web service that returns Json by default but can return Xml if specified in the 'Accept:' header.  It seems that no matter what I set for 'dataType' in my ajax request it always comes back in Xml.  I am not sure if this is because of the browser I am using or if it is the way the Zendesk server sends the request.  I have been using Chrome's built-in javascript console to examine the request/response made by my app and the response is always in Xml, copying and pasting the same request into Fiddler gives me a response in Json.

To look at the data coming back from the request I have done this:

'myAjaxRequest.always' : function(e1, e2, e3) { console.log(e1); console.log(e2); console.log(e3); }

If I don't specify a dataType in my ajax request then e1 comes back as a Document object containing the data I requested, e2 is the status message, and e3 is the jQuery XmlHttpRequest object.  If I specify the dataType as 'json' then e1 is the jQuery XmlHttpRequest object, where as e2 and e3 are nothing.  Maybe this is a result of how my web service handles the request, I am not sure.

In both scenarios mentioned above I am having a heck of a time manipulating the returned data into a nice object that can be passed to a template.  No matter what I try to do to the object in the console I can't seem to pull out the desired data.  This is probably a result of my inexperience with javascript/jQuery but any suggestions or comments are much appreciated.

Thanks,

Chad

2 comments

Please sign in to leave a comment.