问题
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