jquery跨域限制

jquery跨域限制,jquery,cross-domain,jsonp,comet,atmosphere,Jquery,Cross Domain,Jsonp,Comet,Atmosphere,我想使用jquery大气插件连接到comet服务器。问题是服务器位于不同的域上,并且“从V0.7.2开始,Atmosphere JQuery PubSub不支持跨域请求。我们不能将此方法用于JSONP”。有什么办法可以避免这种情况吗?我愿意接受任何解决方案 以下是远程域上给定示例页面中使用的javascript代码: $(document).ready(function() { function callback(response) { // Websocket

我想使用jquery大气插件连接到comet服务器。问题是服务器位于不同的域上,并且“从V0.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);
    });
$(文档).ready(函数(){
函数回调(响应){
//Websocket事件。
$.atmosphere.log('info',[“response.state:”+response.state]);
$.atmosphere.log('info',[“response.transport:”+response.transport]);
detectedTransport=response.transport;
$('ul').append($('
  • ')).text(“响应状态:+response.Status+”传输:+response.Transport)); if(response.transport!=“polling”&&response.state!=“connected”&&response.state!=“closed”){ $.atmosphere.log('info',[“response.responseBody:”+response.responseBody]); 如果(response.status==200){ var数据=response.responseBody; 如果(data.length>0){ dataArray=eval(“(“+data+”); $.each(数据数组、函数(索引、值){ var输出=“”; var数据=价值; 用于(dipData中的属性){ 输出+=属性+':'+dipData[属性]+';'; } $('ul').append($('
  • ')).text(dipData.\uu publicationName+“:“+output)); }); } } 否则{ } } } //从V0.7.2开始,Atmosphere JQuery PubSub不支持 //跨域请求。我们不能对JSONP使用此方法 $.atmosphere.subscribe(document.location.toString()+'webcast',回调); });

    谢谢。

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

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

    谢谢,我以前从未接触过node.js。你能给我一个如何实施的例子吗?谢谢+1表示node.js。作为一个简单的代理服务器,Nginx也非常简单。我在服务器上使用Nginx,也许这是最好的方法;你能给我举个例子说明它是如何工作的吗?谢谢