Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  78] [ 5]  / answers: 1 / hits: 29991  / 13 Years ago, fri, august 19, 2011, 12:00:00

I want to use oembed to get the embed code from youtube links with jQuery:



var url = http://www.youtube.com/watch?v=iwGFalTRHDA;
url = encodeURIComponent(url);

$.getJSON('http://youtube.com/oembed?url='+url+'&format=json', function(data) {
console.log(data);
});


Well I don't get any data.



Funny thing is, that if I browse to the url I get the right response:



http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiwGFalTRHDA&format=json` 


leads me to



{
provider_url: http://www.youtube.com/
title: Trololo
html: <object width=425 height=344><param name=movie value=http://www.youtube.com/v/iwGFalTRHDA?version=3></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><embed src=http://www.youtube.com/v/iwGFalTRHDA?version=3 type=application/x-shockwave-flash width=425 height=344 allowscriptaccess=always allowfullscreen=true></embed></object>
author_name: KamoKatt
height: 344
thumbnail_width: 480
width: 425
version: 1.0
author_url: http://www.youtube.com/user/KamoKatt
provider_name: YouTube
thumbnail_url: http://i2.ytimg.com/vi/iwGFalTRHDA/hqdefault.jpg
type: video
thumbnail_height: 360
}


I also used the jquery oembed plugin, but the onError option is always thrown, also if the request was successful.



I'm really looking forward for some ideas...


More From » jquery

 Answers
29

Actually the problem is you're violating the browser same origin policy with a cross domain ajax request. There a few work potential work arounds -- unfortunately the best JSONP, isn't implemented by YouTube. The next best is using Flash for transport. This is used by YUI-IO utility. Also you can see Jquery suggestions here.


[#90525] Thursday, August 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;