问题描述
我想从发送本地服务器的请求到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-OriginCode 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:
编辑:截至2012年5月18日,在YouTube API支持CORS:的
As of May 18, 2012, the YouTube API supports CORS: http://apiblog.youtube.com/2012/05/unlocking-javascripts-potential-with.html
这篇关于没有被访问控制允许来源允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!