开发者

jQuery call synchronously

I'm combining 2 jQuery plugins, Fancybox and Embedly (like jQuery oembed).

In the Fancybox onStart event I get the url of link, make a call to the oembed service and push the response (a video) back into the lightbox.

Well at least that's what I want to happen :) I'm getting a response back from the oembed provider but I think t开发者_JAVA百科he onStart function has already completed by the time this happens.

The code:

$('a').fancybox({
    type: 'html',
    onStart: function(selectedArray, selectedIndex, selectedOpts) {
            var url = selectedArray[selectedIndex].href;
            $.embedly(url, {
                success: function (oembed, dict) {
            selectedOpts.content = oembed.html;
                }
            });
    }
});

It seems I need to process the call synchronously?

Thanks

Ben


Try this

$('a').each(function(i, a){
            var url = a.href, $a = $(a);
            $.embedly(url, {
                success: function (oembed, dict) {
                     $a.fancybox({
                     type: 'html',
                     onStart: function(selectedArray, selectedIndex, selectedOpts) {
                        selectedOpts.content = oembed.html;

                               }
                     });
                   }

                }
            });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜