簡體   English   中英

如何使用get方法跨域jquery ajax響應?

[英]how to cross-domain jquery ajax responce using get method?

如何使用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

您的網址回調函數缺少= 這是正確的網址。 然后嘗試一下。

  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} }); 

嘗試這個:

$.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);
   }      
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM