get youtube oembed json with ajax

◇◆丶佛笑我妖孽 提交于 2019-12-08 01:48:59

问题


I am try to get oembed code of youtube link with ajax but it returns always error I am using ajax with Jquery

    $.ajax({
        method: 'GET',
        dataType :'json',
        url:'http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=wbp-3BJWsU8&format=json',
        success:function(data){
            alert(data);
        },
        error: function(error) {
            alert(error);
        }
    });

回答1:


try the following

 $.ajax({
            url: 'http://query.yahooapis.com/v1/public/yql',
                data: {
                    q: "select * from json where url ='http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=wbp-3BJWsU8&format=json'",
                    format: "json"
                },
                dataType: "jsonp",
            success: function (data) {

                alert(JSON.stringify(data));


            },
            error: function (result) {
                alert("Sorry no data found.");
            }
        });



回答2:


Try this :-

live Demo :-

http://jsfiddle.net/YFtvU/8/

$.ajax({
            url: 'http://query.yahooapis.com/v1/public/yql',
                data: {
                    q: "select * from json where url ='http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=wbp-3BJWsU8&format=json'",
                    format: "json"
                },
                dataType: "jsonp",
            success: function (data) {

                alert(JSON.stringify(data));


            },
            error: function (result) {
                alert("Sorry no data found.");
            }
        });


来源:https://stackoverflow.com/questions/15949969/get-youtube-oembed-json-with-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!