用JavaScript替换Skyscanner Api。获取响应没有'访问控制 - 允许 - 来源'头

时间:2016-05-22 14:23:42

标签: javascript ajax skyscanner

当我使用Skyscanner Api创建会话时,我可以获得201响应,这意味着创建了会话。 但有一个例外,结束我的剧本, " No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' null'因此不允许访问"。 这是我的代码。

    var apikey = "prtl6749387986743898559646983194";
    var url = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/?   apikey=" + apikey;
    $.ajax({
        type:"POST",
        url:url,
        dataType:"json",
        crossDomain: true,
        Accept:"application/json",
        data:{
            country:"UK",
            currency:"GBP",
            locale:"en-GB",
            locationSchema:"iata",
            apikey:"prtl6749387986743898559646983194",
            grouppricing:"on",
            originplace:"EDI",
            destinationplace:"LHR",
            outbounddate:"2016-05-29",
            inbounddate:"2016-06-05",
            adults:1,
            children:0,
            infants:0,
            cabinclass:"Economy" 
        },
        contentType:"application/x-www-form-urlencoded",
        success:function(){
            console.log("success");
        }
    });

1 个答案:

答案 0 :(得分:-1)

应在服务器端启用跨域。如果没有完成。您的代码无法正常工作。