I’m having a problem. I have this code:
setInterval(function() {
$.ajax({ url: url, success: function(data, count){
var obj = jQuery.parseJSON(data);
var content = obj.results[0].content;
}})
}, 2000)
Now this code is running every 2 seconds and making an ajax call. I keep getting the error that obj is null on this line:
var content = obj.results[0].content;
I’m pretty sure it’s because parseJson hasn’t finished when the parser reaches this line. I need a way to say while obj = null don’t run the var content = obj.results[0].content; code.
Hope this makes sense.
If you want to be anal about it:
But I don’t really think that’s the problem.. that callback is only called after everything is done. And the JSON parsing is synchronous. Are you sure the server is returning the right data?
FYI, you can also provide the
dataTypeoption forjQuery.ajaxcalls so the JSON parsing is done automatically.