1

I'm trying to do an ajax call on a static teams.json file:

{
    "employees": [
        { "firstName":"John" , "lastName":"Doe" }, 
        { "firstName":"Anna" , "lastName":"Smith" }, 
        { "firstName":"Peter" , "lastName":"Jones" }
    ]
}

Here is my exact AJAX call:

this.testData = function() {
    return $.ajax({
        type: "GET",
        url: "js/dummy-data/teams.json",
        dataType: "json",
        async: false,
        success: function(data) {
            console.log(data);
        }
    });
}

The problem is that when I call testData(), What I see in the network tab of my Chrome inspector tools is something called "OPTIONS" as opposed to "GET".

I also see an error which states "Origin null is not allowed by Access-Control-Allow-Origin" error...

All I want to do is return the json object and console.log it out. Where am I going wrong?

lorenzoid
  • 1,812
  • 10
  • 33
  • 51
  • 1
    Copy/paste the URL in your code into a new browser window's address bar. See what comes back. Your server may not be configured to spit out JSON files. – Diodeus - James MacFarlane Sep 16 '13 at 18:47
  • 3
    Check out this http://stackoverflow.com/questions/8456538/origin-null-is-not-allowed-by-access-control-allow-origin. It has a good explaination of Same Origin Policy issues. – Barbara Laird Sep 16 '13 at 18:49
  • I'm assuming this file is running off your local machine (`file:///`), right? To use AJAX, your file needs to be on a webserver. – gen_Eric Sep 16 '13 at 18:59
  • Yes. It was. I found that out as well. Thanks! – lorenzoid Sep 17 '13 at 22:58

0 Answers0