0

I have a html page in which i am taking out the data of static json file which is renamed as .js file and put up some where on a local server say 10.211.20.62:8080/case1/county_json.js

i am using the code which is working properly in ie 6, 7, 8 but not in google chrome, firefox and other browsers.

Javascript code

function setfilter() {
$.getJSON('http://10.211.20.62:8080/case1/county_json.js', function (data) {
}).error(function(jqxhr, textStatus, errorThrown) {
alert(errorThrown);   
});
}


$(document).ready(function () { 
jQuery.support.cors = true;
setfilter();
});

what should be the problem? PLEASE HELP!

2 Answers2

0

If I understand correctly, your HTML page isn't located on the same server as the data. Then the problem is the same-origin policy (see https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript). MSIE probably works because there you have special rules for the local zone. But in general you cannot load JSON data from a different server.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • "you cannot load JSON data from a different server" so... what's JSONP for? – balexandre Jun 08 '11 at 11:42
  • @balexandre: I meant "without cooperation from that different server". If you can change the format of data returned by the server or if you can add the headers required for a cross-site XMLHttpRequest it will work. – Wladimir Palant Jun 08 '11 at 11:46
0

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead (http://api.jquery.com/jQuery.getJSON/).

Try:

$.getJSON('http://10.211.20.62:8080/case1/county_json.js?callback=?', function (data) { }).error(function(jqxhr, textStatus, errorThrown) { alert(errorThrown);
});

Brent
  • 158
  • 5