0

如何使用 jQuery 或 node.js 对 json 文件进行异步跨域请求(GET)?我有我的 api,我只需要向文件发出请求

$.ajax({
    type: 'GET',
    url: "https://api.flightstats.com/flex/airports/rest/v1/json/active?appId=3a311b8b&appKey=5d67203e8afab7fe8d01e0debf177171",
    processData: true,
    data: {},
    dataType: "json"

});

结果

XMLHttpRequest
XMLHttpRequest cannot load https://api.flightstats.com/flex/airports/rest/v1/json/active?appId=3a311b8b&appKey=5d67203e8afab7fe8d01e0debf177171. Origin https://developer.flightstats.com is not allowed by Access-Control-Allow-Origin.

或者

$.ajax({
    type: 'GET',
    url: "https://api.flightstats.com/flex/airports/rest/v1/json/active?appId=3a311b8b&appKey=5d67203e8afab7fe8d01e0debf177171?callback?",
    processData: true,
    data: {},
    dataType: "jsonp"        
});

结果

undefined
4

2 回答 2

0

您的 url 回调函数丢失=。这是正确的网址。然后尝试一下。

  1. 确保您没有在控制台中收到任何 404 错误。
  2. 检查控制台是否有任何其他错误。

    $.ajax({
        type: 'GET',
        url: "https://api.flightstats.com/flex/airports/rest/v1/json/active?appId=3a311b8b&appKey=5d67203e8afab7fe8d01e0debf177171?callback=?",
        processData: true,
        data: {},
        dataType: "jsonp",
        success:function(data){//do some thing with data},
        error:function(xhr, ajaxOptions, thrownError){//do with ajax errors}
    });
    
于 2013-01-30T08:27:40.207 回答
0

尝试这个:

$.ajax({
   type: 'GET',
   url: "https://api.flightstats.com/flex/airports/rest/v1/json/active?appId=3a311b8b&appKey=5d67203e8afab7fe8d01e0debf177171?callback=?",
   dataType: "jsonp",
   success:function(data){
       console.log(data);
   }      
});
于 2013-01-30T08:30:40.763 回答