I have uploaded this data to rackspace cloud files:
{"foo": "bar"}
It lives at this url: http://c192531.r31.cf1.rackcdn.com/test.json
It is served as Content-Type application/json, and when accessed with a browser you get a promt to download. The file has the expected content.
When I try to access it with jquery 1.4.2 with this snippet
<script>
$(document).ready(function($) {
url = 'http://c192531.r31.cf1.rackcdn.com/test.json';
$.getJSON(url, function (data) {
alert( data );
});
});
</script>
it alerts null.
What did I do wrong?
Is the page containing this script hosted on the same domain (http://c192531.r31.cf1.rackcdn.com)? If not you are probably hitting the same origin policy restriction which prevents you from sending cross domain AJAX requests.
A possible workaround would be to use JSONP but you will need to make the remote URL return a JSONP string or if you cannot modify it setup a server side script which would act as a bridge between your domain and the remote domain and then send the AJAX request to this bridge script.