【问题标题】:No 'Access-Control-Allow-Origin' when accessing gisgraphy api访问 gisgraphy api 时没有“Access-Control-Allow-Origin”
【发布时间】:2014-04-16 07:01:51
【问题描述】:

我正在尝试使用此代码访问 gisgraphy api:

$('[id$=PlaceOfDeparture]:not(.ui-autocomplete-input)').live('focus', function() {
    $(this).autocomplete({
        source: function (request, response) {
            $.ajax({
                type: 'POST',
                datatype: 'jsonp',
                url: 'http://services.gisgraphy.com/fulltext/fulltextsearch?q='+ request.term,
                //data: {
                //    q: request.term
                //},

                success: function(res) {
                    console.log("Success: " + res);
                },
                error: function(res) {
                    console.log("Error: " + res);
                }
            });
        }
    });
});

当我这样做时,我得到错误: XMLHttpRequest 无法加载 http://services.gisgraphy.com/fulltext/fulltextsearch?q=viborgsslingan。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'mylocalhost' 不允许访问。 如果我按下链接,我会在浏览器中得到我想要的 xml。不知何故,它不会进入我的代码。我已经搜索了一下这个问题,但它似乎是 gisgraphy 服务器上的一个安全问题......我可以做些什么来使这个跨域访问工作?

【问题讨论】:

    标签: ajax api post request cross-domain


    【解决方案1】:

    我搜索了一下这个问题,但它似乎是 gisgraphy 服务器上的一个安全问题......

    这不是安全问题问题,而是相反。 Same Origin Policy 禁止您通过 AJAX 从 JS 中的其他域请求数据,除非远程域发出信号,它希望明确授予您访问(这称为 @987654322 @)。

    如果您访问的服务不提供该服务,并且没有其他不受 SOP 限制的格式 - 例如 f.e. JSONP——那么你就无法通过 JavaScript 在客户端获取该数据。

    【讨论】:

      猜你喜欢
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2018-07-18
      • 1970-01-01
      • 2018-03-28
      • 2016-05-13
      • 2018-12-12
      相关资源
      最近更新 更多