谷歌广场API - 否“访问控制 - 允许 - 原产地”标头的请求的资源present。原产地'空',因此没有允许访问 [英] Google Place API - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access

查看:483
本文介绍了谷歌广场API - 否“访问控制 - 允许 - 原产地”标头的请求的资源present。原产地'空',因此没有允许访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的jQuery的。

我使用谷歌广场API。

我要得到什么地方建议型帮扶。

所以,我所做的是 -

  VAR Google_Places_API_KEY =AIzaSyAK08OEC-B2kSyWfSdeCzdIkVnT44bcBwM; //获取它 -  HTTPS://$c$c.google.com/apis/console/ noredirect#项目:647731786600:访问?
VAR LANGUAGE =EN; //en代表英语,NL对荷兰的语言


VAR Auto_Complete_Link = "https://maps.googleapis.com/maps/api/place/autocomplete/json?key="+Google_Places_API_KEY+"&types=geo$c$c&language="+language+"&input=Khu";
$ .getJSON(Auto_Complete_Link,函数(结果)
{
    $每个(结果,功能(我,场)
    {
        //$("div").append(field +);
        //警报(I +==+领域);
        console.error(I +==+领域);
    });
});
 

因此​​,在什么环节,我请求是 -

  

<一个href="https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyAK08OEC-B2kSyWfSdeCzdIkVnT44bcBwM&types=geo$c$c&language=en&input=Khu" rel="nofollow">https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyAK08OEC-B2kSyWfSdeCzdIkVnT44bcBwM&types=geo$c$c&language=en&input=Khu

如果我去与浏览器这个环节,我可以得到的输出喜欢它(请尽量CK) -

但是,如果我试图用jQuery的 .getJSON 阿贾克斯,我收到了我的请求阻止此消息 -

所以XMLHTT prequest被阻止,因为 -

  

没有访问控制 - 允许 - 原产地标头的请求的资源present。原产地'空',因此没有允许访问。

我已经检查了计算器对于这个问题的解决方案,并通过<一个href="http://stackoverflow.com/questions/20518524/no-access-control-allow-origin-header-is-$p$psent-on-the-requested-resource-or">here, [在此<一个href="http://stackoverflow.com/questions/20518524/no-access-control-allow-origin-header-is-$p$psent-on-the-requested-resource-or">4和<一href="http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-$p$psent-on-the-requested-resource">here,但不能让我的完美的解决方案。

任何人都可以告诉我吗?

感谢您帮助。

解决方案

AJAX请求是唯一可能的,如果端口,协议,发送者和接收者的领域都是平等的,如果不是可能导致CORS。 CORS代表跨域资源共享,并要在服务器端支持。<​​/ P>

  

解决方案

JSONP

JSONP或JSON与填充是在Web浏览器上运行,从服务器请求一个不同的域数据的JavaScript程序中使用的通信技术,一些禁止的典型的Web浏览器,因为同源策略的。

像这样的东西可以帮助你队友..:)

  $。阿贾克斯({
            网址:Auto_Complete_Link,
            键入:GET,
            数据类型:JSONP,
            缓存:假的,
            成功:函数(响应){
                警报(响应);
            }
        });
 

I am new in jQuery.

I am using Google Place API.

What I want to get suggestion of place for type helping.

So, what I have done is-

var Google_Places_API_KEY = "AIzaSyAK08OEC-B2kSyWfSdeCzdIkVnT44bcBwM";      //Get it from - https://code.google.com/apis/console/?noredirect#project:647731786600:access
var language = "en";        //'en' for English, 'nl' for Nederland's Language


var Auto_Complete_Link = "https://maps.googleapis.com/maps/api/place/autocomplete/json?key="+Google_Places_API_KEY+"&types=geocode&language="+language+"&input=Khu";
$.getJSON(Auto_Complete_Link , function(result)
{
    $.each(result, function(i, field)
    {
        //$("div").append(field + " ");
        //alert(i + "=="+ field);
        console.error(i + "=="+ field);
    });
});

So in what link I am requesting is -

https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyAK08OEC-B2kSyWfSdeCzdIkVnT44bcBwM&types=geocode&language=en&input=Khu

And if I go to this link with browser, I can get output like it (please try to ck)-

But if I try with jQuery's .getJSON or .ajax, I am getting my request blocked with this message-

.

SO the XMLHTTPRequest is blocked because of -

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

I have checked in StackOverflow for this problem solution and go through here, [here4 and here, but can't get my solution perfectly.

Can anyone please enlighten me?

Thanks in advance for helping.

解决方案

AJAX Requests are only possible if port, protocol and domain of sender and receiver are equal,if not might lead to CORS. CORS stands for Cross-origin resource sharing and has to be supported on the server side.

Solution

JSONP

JSONP or "JSON with padding" is a communication technique used in JavaScript programs running in web browsers to request data from a server in a different domain, something prohibited by typical web browsers because of the same-origin policy.

Something like this might help you mate.. :)

$.ajax({
            url: Auto_Complete_Link, 
            type: "GET",   
            dataType: 'jsonp',
            cache: false,
            success: function(response){                          
                alert(response);                   
            }           
        });    

这篇关于谷歌广场API - 否“访问控制 - 允许 - 原产地”标头的请求的资源present。原产地'空',因此没有允许访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆