0

我想使用 jquery 气氛插件连接到彗星服务器。问题是服务器位于不同的域上,“从 v 0.7.2 开始,Atmosphere JQuery PubSub 不支持跨域请求。我们不能将此方法用于 JSONP”。有什么办法可以规避这种情况吗?我愿意接受任何解决方案!

这是远程域上给定示例页面中使用的 javascript 代码:

    $(document).ready(function() {

    function callback(response) {
        // Websocket events.
            $.atmosphere.log('info', ["response.state: " + response.state]);
        $.atmosphere.log('info', ["response.transport: " + response.transport]);

        detectedTransport = response.transport;
        $('ul').append($('<li></li>').text("Resp Status : "+response.status+" Transport : "+response.transport));
        if (response.transport != 'polling' && response.state != 'connected' && response.state != 'closed') {
        $.atmosphere.log('info', ["response.responseBody: " + response.responseBody]);
        if (response.status == 200) {
            var data = response.responseBody;
            if (data.length > 0) {
               dataArray = eval("("+data+")");

               $.each(dataArray, function(index, value){
                 var output = '';
                 var dipData = value;
                 for (property in dipData) {
                    output += property + ': ' + dipData[property]+'; ';
                 }

                 $('ul').append($('<li></li>').text(dipData.__publicationName+":"+output));
               });
            }
        }
        else{

        }
        }
    }

       // As of v 0.7.2, Atmosphere JQuery PubSub does not support
       // cross domain requests. We cannot use this method for JSONP
       $.atmosphere.subscribe(document.location.toString() + 'webcast', callback);
    });

谢谢

4

2 回答 2

1

最简单的选择可能是在您的域上建立一个 Node.js 代理来代理您对外部域的请求。

于 2011-09-18T14:45:15.803 回答
0

最简单的解决方案是:对非 IE 浏览器和 XDR 或跨域请求使用 CORS。您只需修改 HTTP 标头并使用 Allow_Access。

于 2012-04-25T14:37:32.057 回答