Reputation: 121
Can't seem to figure out what's wrong with the simple getJSON call below. It's working fine in FF12 but not in IE8 and Chrome19.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('data.json',function(result){
alert("success");
});
});
</script>
Please note that the following is working fine in all the browsers:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
alert("success");
});
</script>
So, apparently, something's wrong with the getJSON call.
Any ideas?
Thanks.
Update: Thanks to samy.vilar I was able to get it working. Here are the things I corrected :-
Hosted the file to a server(IIS 7, in this case): To make an AJAX request the files got to be hosted on a server. I was trying to access data.json using the file system.
Added the MIME type for extension .json in IIS 7.
That did it. Though I still wonder how it was working in FF earlier when we can't complete an AJAX request without hosting.
Upvotes: 3
Views: 4239
Reputation: 712
How to follow the following instructions in ubuntu ? Open the properties for the server in IIS Manager and click MIME Types Click "New". Enter "JSON" for the extension and "application/json" for the MIME type.
Upvotes: 0
Reputation: 341
This is the same problem with D3.js loading json data local.
The patches for D3.js can be found here:
https://github.com/jasondavies/d3/commit/95b1eaaf68a1e75e6cf95b88d7e4bbc834b8489d
The patches being applied makes local json data working.
I hope that these patches can be applied as well to jquery-1.7.2
I got same problem with jQtouch b4 which uses jQuery-1.7.2. Previous version of jQTouch b1 that uses jQuery-1.3.2 works fine.
Upvotes: 0
Reputation: 11120
Since IIS doesn't support json by default you can try renaming the data.json to data.html this way IIS won't complain ;) ... just update getJSON to $.getJSON('data.html,...
if you want to enable .json file extension simply follow this instructions.
Open the properties for the server in IIS Manager and click MIME Types
Click "New". Enter "JSON" for the extension and "application/json" for the MIME type.
Upvotes: 3