0

Hi I'm testing a rest api call by http://airportcode.riobard.com that allows me look up airport codes. When I type in the following into my browser:

http://airportcode.riobard.com/search?q=las%20vegas&fmt=JSON

I get the correct json. However when I make a json jQuery call:

var url = 'http://airportcode.riobard.com/search?q=las vegas&fmt=JSON';

// Request json
jQuery.getJSON(url, function(data){
    console.log(data);
});

I get a 200 which is good, but the response object is empty. Why is this happening to me?

Thanks.

Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133
  • It's not. For one, I did not know the problem was a cross domain issue. The fact that this question points out some anamolous behaviour that describes a cross domain issue vs the other question that begins by stating it is a cross domain question that deals with jsonp, means that this is a different question. The other thing that differs with my question is that my api's don't offer jsonp capability and the other questions asks about it. Different questions. – Dr.Knowitall Feb 11 '14 at 07:36

2 Answers2

1

So the deal is, I can't access the json because it does not come from the same origin as the rest of my javascript. It is a good example of cross-site scripting and I forgot about it.

Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133
0

Check the console, it may display an

Origin ___________ is not allowed by Access-Control-Allow-Origin.

that means you need to add some headers to your responses in the server. specifically the Access-Control-Allow-Origin to "*" or you can try using a JSONP request. with $.JSONP

Viktor Justo
  • 203
  • 2
  • 9
  • Thats not in the request header. The origin is null because I'm running the script from local. Unfortunately I think I'm just going to have to write PHP rest api to act as a courier for this issue. – Dr.Knowitall Feb 11 '14 at 07:30