gpt4 book ai didi

c# - jquery 1.5 问题与 $.getJSON 请求到 Vimeo

转载 作者:行者123 更新时间:2023-11-30 21:17:12 27 4
gpt4 key购买 nike

我正在尝试向 vimeo 发出 ajax 请求,以从我们的网络应用程序所需的 vimeo 视频中获取数据。

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();
});

当我在像 IE 这样的浏览器中输入 vimeoDataUrl 时,我得到了预期的 json 结果,但是当我在 firebug 中查看请求时,我得到了一个带有 200 状态的空响应。有人可以帮我吗?问题出在 vimeo 还是我做错了什么?

最佳答案

您不能向不同域( JS docswikipedia )发出 json 请求。
你需要使用jsonp

如果您取消注释 url 中的最后一部分,&callback=? 它工作得很好.. 因为如果 jquery 在 url 中找到它,它将使用 jsonp。

所以用

var vimeoDataUrl = "http://vimeo.com/api/oembed.json?url=http://vimeo.com/" + vimeoId + "&callback=?";

来自 getJsondocs

JSONP

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

Additional Notes:

  • Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
  • Script and JSONP requests are not subject to the same origin policy restrictions.

演示在 http://www.jsfiddle.net/gaby/gQaXD/

关于c# - jquery 1.5 问题与 $.getJSON 请求到 Vimeo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4920041/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com