Ok, I'm trying to get a JSON file from a URL with the following jQuery code.
$.ajax({
url: 'http://example.com/example.json',
dataType: 'json',
type: 'GET',
async: true,
cache: true,
crossDomain: true
});
However, when the request fires, Firebug indicates that an error occurred but doesn't tell me what it was.
I can get to the URL in my browser with no problems and the JSON is perfectly valid (according to http://www.freeformatter.com/json-validator.html).
Any suggestions?
EDIT:
Ok, changing the contentType to jsonp has gotten me a step further. My JSON looks like this (http://pastebin.com/hSAP30zv), but Firebug is saying:
SyntaxError: invalid label
"item" : {
^
Any more suggestions?
crossDomain? If you're hoping to use JSONP, you need to emit a JSONP response rather than JSON. If you're using CORS, you should passxhrFields: { withCredentials: true }instead (api.jquery.com/jQuery.ajax)dataType: 'json'andcrossDomain: truework together. You only need to usecrossDomain: trueif you want to enforce cross-domain behavior on the same domain. So, I assume that you actually really make a cross-domain request, which returns JSON. That won't work unless the server supports CORS. Or it has to return JSONP and you have to tell jQuery to expect JSONP withdataType: 'jsonp'.dataType:'jsonp'did it. Now it's giving trouble parsing JSON?