Together we can defeat the internet

Tag: AJAX

update: I really should RTFM. dataType can go in any place when listing options. If I had read the docs…

update: I really should RTFM. dataType can go in any place when listing options. If I had read the docs a bit more carefully, I would’ve noticed that the reason I started getting a JSON object back instead of a XMLHttpRequest is that I specificed ‘success’ with a callback instead of ‘complete’.

Though I did figure out a better way of parsing the returned object
var myCallback=function(jsonObj){
for (k in jsonObj) {
if (iWantToCheck(k)) {
useValueOfK(jsonObj[k]);
}
}
}

Found out something interesting today. I normally try to stick to a simple AJAX return such as html or xml that is easy to manipulate. Today, I couldn’t accomplish my task without the help of JSON. I’m sure there’s other ways I could’ve told JS how to react on different succeed or fail conditions but JSON was the first one that came to mind. On to the story…I set the dataType on my ajax options to ‘json’ and was surprised to find that I was still getting a XMLHttpRequest object instead of the expected JSON object. I tried sending ‘Content-Type: application/json’ header, tried a bunch of other things I can’t remember at the moment.