Reputation: 13
I want to call client side ajax request with cross domain for following URL:
http://www.youtube.com/get_video_info?video_id=IZ-_3Ug3wqU
$.ajax({
type: "GET",
url: "http://youtube.com/get_video_info",
data: { video_id: "IZ-_3Ug3wqU" },
dataType: "text",
success: function (response) {
alert('success');
},
error: function (error) {
alert('error');
},
complete: function () {
alert('complete');
}
});
Please help me
Thanks
Upvotes: 1
Views: 1920
Reputation: 36
As far as I can see, the request is OK.
Have you allowed CORS by adding the Access-Control-Allow-Origin
header?
If you didn't, in .htaccess, add
<IfModule mod_headers.c>
Header add Access-Control-Allow-Origin "http://youtube.com"
</IfModule>
EDIT:
The only "good practices" way I can think to do this is using the header, you can check http://enable-cors.org/server_aspnet.html and see if any of this configurations work.
Other way may be using the YoutubeAPI from your server to access directly this information that way, and then calling this script with the ajax call (the script working as a "bridge").
Upvotes: 0
Reputation: 2599
I believe the proper way to access this data is through the YouTube API created specifically for this purpose.
The request would looks something like the following:
https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
&part=snippet,contentDetails,statistics,status
Upvotes: 1