I’m trying to make an ajax-request to vimeo to get data from an vimeo video needed for our webapplication.
var vimeoDataUrl = "http://vimeo.com/api/oembed.json?url=http://vimeo.com/" + vimeoId; //+ "&callback=?";
console.log(vimeoDataUrl); //http://vimeo.com/api/oembed.json?url=http://vimeo.com/16630327
$.getJSON(vimeoDataUrl, function (json, textStatus) {
if (json != null) {
var title = json.title;
var videoWidth = json.width;
var videoHeight = json.height;
if (title != null && videoWidth != null && videoHeight != null) {
var vimeoImageUrl = json.thumbnail_url;
$('#largeImageUrl').val(vimeoImageUrl);
$('#videoName').val(title);
$('#videoWidth').val(videoWidth);
$('#videoHeight').val(videoHeight);
hasValidVideoUrl = true;
}
}
else
{
//an message is shown
}
$('#videoName, #placeVideo').removeAttr('disabled');
$('img#loading').remove();
});
When I enter the vimeoDataUrl in an browser like IE i’m getting the json result as expected, but as soon as i’m looking at the request in firebug i’m getting an empty response with an 200-status. Can someone help me out here? Is the problem located at vimeo or am I doing something wrong?
You cannot make json request to different domains ( JS docs and wikipedia).
You need to use jsonp
If you un-comment the final part in your url, the
&callback=?it works just fine .. because jquery will use jsonp if it finds it in the url.so use
from the
getJsondocsDemo at http://www.jsfiddle.net/gaby/gQaXD/