使用jQuery + ajax加载Vimeo视频

时间:2012-03-27 10:59:08

标签: jquery ajax video vimeo oembed

我在使用带有jQuery的OEMBED api阅读Vimeo视频时遇到了麻烦。

我的javascript是

    function loadVideo(params, callback) {
        $.ajax({
            type : "GET",
            url : "http://www.vimeo.com/api/oembed.json",
            data : params,
            dataType : "json",
            success : function(result) {
                alert("calling callback");
                callback(result);
            },
            error : function(error) {
                var s = "";
                $.each(error, function(name, value){
                    s += name + ": " + value + "\n";
                });
                alert(s);
            }
        });
    };

我将此功能称为

    loadVideo({
        "url" : $(this).attr("url"),
        "title" : $(this).attr("show-title"),
        "byline" : $(this).attr("show-byline"),
        "portrait" : $(this).attr("show-portrait"),
        "color" : "ffffff",
        "width" : 120
    }, function(result) {
        alert("Setting video content");
        $(this).html(unescape(result.html));
    });

其中$(this)是必须加载视频的元素。

检查请求

    Request URL:http://vimeo.com/api/oembed.jsonurl=https%3A%2F%2Fvimeo.com%2F38578157&title=false&byline=false&portrait=false&color=ffffff&width=120&callback=%3F
    Request Headers
    Referer:http://localhost:8080/artwriter/art
    User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
    Query String Parameters
    url:https://vimeo.com/38578157
    title:false
    byline:false
    portrait:false
    color:ffffff
    width:120

此请求看起来是正确的(如果我在浏览器中复制并粘贴,我会得到这个json结果

{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"http:\/\/vimeo.com\/","title":"Test video 1","author_name":"Stefano Cazzola","author_url":"http:\/\/vimeo.com\/user10866085","is_plus":"0","html":"    <iframe src=\"http:\/\/player.vimeo.com\/video\/38578157?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff\" width=\"120\" height=\"90\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen><\/iframe>\n\n\n","width":120,"height":90,"duration":165,"description":"","thumbnail_url":"http:\/\/b.vimeocdn.com\/ts\/265\/600\/265600694_100.jpg","thumbnail_width":100,"thumbnail_height":75,"video_id":38578157}

然而出现了问题,我最终遇到了ajax错误回调。

有什么想法吗?

0 个答案:

没有答案