slideshare oembed api 和 Access-Control-Allow-Origin

slideshare oembed api and Access-Control-Allow-Origin

我想嵌入一个基于 URL 的 slideshare iframe。 http://www.slideshare.net/developers/oembed 说我应该能够获得关于资源的 JSON 对象,其中是要使用的嵌入代码。例如。如果我打开

Reference Link

在浏览器中,我得到 JSON。如果我通过 jquery

打开相同的

$.getJSON('http://www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/lyndadotcom/code-drivesworld12&format=json', function (obj) { console.log(obj) });

然后我得到

XMLHttpRequest cannot load http://www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/lyndadotcom/code-drivesworld12&format=json&callback=myFunction. No 'Access-Control-Allow-Origin' header is present on the requested resource.

理想情况下,我还想从外部 link 控制 slideshare - 这个页面 - http://www.slideshare.net/developers - 如果你关注 SlideShare Player API - 这是可能的一个 404 页面。

通过谷歌搜索 slideshare 开发者只是 link 让我看到许多共享的幻灯片,而不是存在或有效的实际帮助...grrr

当您尝试从另一个域加载 JSON 时失败,因为存在域边界您无法 cross.To 避免这种情况,您必须使用 JSON with Padding。 JSONP 或 "JSON with padding" 是 Web 浏览器中 JavaScript 程序 运行 中使用的一种通信技术,用于从不同域中的服务器请求数据,由于同源,典型的 Web 浏览器禁止使用这种技术政策。试试下面的代码 mate.Hope 这可能对你有帮助。 :)

$.ajax({
    type: "GET",
    url: 'http://www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/lyndadotcom/code-drivesworld12&format=jsonp',
    dataType: 'jsonp',
    success: function (data) {
        $('.dynamic').html(data.html);
    }
});

Fiddle here