Muhammad Usman
Muhammad Usman

Reputation: 10926

is not allowed by Access-Control-Allow-Origin

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

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);

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

Upvotes: 2

Views: 7871

Answers (1)

monsur
monsur

Reputation: 47897

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://code.google.com/apis/youtube/2.0/developers_guide_json.html

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

Upvotes: 5

Related Questions