没有被访问控制允许来源允许 [英] is not allowed by Access-Control-Allow-Origin

查看:288
本文介绍了没有被访问控制允许来源允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从发送本地服务器的请求到YouTube服务器BU铬控制台显示以下错误

I am trying to send request from local server to youtube server bu the chrome console is displaying the following error

不会被允许访问控制允许来源
code是

is not allowed by Access-Control-Allow-Origin Code is

http.open("POST", url, true);
    http.setRequestHeader("Authorization", "AuthSub token=" + AccessToken);
    http.setRequestHeader("GData-Version", 2);
    http.setRequestHeader("X-GData-Key", "key=" + dev_key);
    http.setRequestHeader("Content-Length", sendXML.length);
    http.setRequestHeader("Content-Type", "application/atom+xml; charset=UTF-8");



    http.onreadystatechange = function() 
    {
        if(http.readyState == 4) {
            alert(http.responseXML);
            alert(http.responseText);
            document.getElementById("response").innerHTML=http.getAllResponseHeaders();
        }
    }
    http.send(sendXML);

这将通过实施JSONP回调函数来完成。但我没有想法如何实现它结果
PLZ指导我。

It will be done by implementing JSONP callback function. But I do not have idea how to implement it
plz guide me

推荐答案

您不能使用XMLHtt prequest对YouTube的API,因为浏览器的同源策略。相反,你应该使用YouTube API的JSON-P功能:

You cannot use XMLHttpRequest against the YouTube API because of the browser's same origin policy. Instead, you should use the YouTube API's json-p functionality:

HTTP://$c$c.google.com/的API / YouTube的/ 2.0 / developers_guide_json.html

编辑:截至2012年5月18日,在YouTube API支持CORS:的 http://apiblog.youtube.com/2012/05/unlocking-javascripts-potential-with.html

As of May 18, 2012, the YouTube API supports CORS: http://apiblog.youtube.com/2012/05/unlocking-javascripts-potential-with.html

这篇关于没有被访问控制允许来源允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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