MrSnrub MrSnrub - 2 years ago 83
PHP Question

Cannot call getJSON method to fetch data

I am trying to fetch some JSON data. I can access the data just fine in a regular web browser, like this:, but I cannot get it to work in jQuery. What am I doing wrong?

Please take a look at my jsFiddle:

var tsp_api = '//';

$.getJSON( tsp_api, function(json) {

// This alert never gets called.

// Set the variables from the results array
var data = json;
// console.log('Data : ', data);

// Set the div's text


Answer Source

You cannot get the result because the remote site doesn't have CORS enabled: If you look at the console, you'll see:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at (Reason: CORS header 'Access-Control-Allow-Origin' missing).

You can bypass CORS by using something like, i.e.:

$.getJSON('', function(data){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download