我想使用oembed从youtube链接获取jQuery的嵌入代码:
I want to use oembed to get the embed code from youtube links with jQuery:
var url = "www.youtube/watch?v=iwGFalTRHDA"; url = encodeURIComponent(url); $.getJSON('youtube/oembed?url='+url+'&format=json', function(data) { console.log(data); });我没有得到任何数据。
有趣的是,如果我浏览到网址,我会得到正确的回复:
Funny thing is, that if I browse to the url I get the right response:
www.youtube/oembed?url=http%3A%2F%2Fwww.youtube%2Fwatch%3Fv%3DiwGFalTRHDA&format=json`引导我
{ provider_url: "www.youtube/" title: "Trololo" html: "<object width="425" height="344"><param name="movie" value="www.youtube/v/iwGFalTRHDA?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="www.youtube/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: "www.youtube/user/KamoKatt" provider_name: "YouTube" thumbnail_url: "i2.ytimg/vi/iwGFalTRHDA/hqdefault.jpg" type: "video" thumbnail_height: 360 }我还使用了jquery oembed插件,但是如果请求成功,也会抛出onError选项。
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...
推荐答案实际上问题是你违反了浏览器相同的源策略和跨域ajax请求。有一些潜在的工作方法 - 遗憾的是最好的 JSONP未实施通过YouTube 。接下来最好的是使用Flash进行传输。这由 YUI-IO实用程序使用。您也可以在这里看到 Jquery建议。
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.
更多推荐
使用oembed嵌入youtube视频
发布评论