我想连接到使用jquery氛围插件的彗星服务器。问题是服务器位于不同的域中,并且“自v 0.7.2开始,Atmosphere JQuery PubSub不支持跨域请求,我们不能使用此方法用于JSONP”。有什么办法可以绕过这个吗?我愿意接受任何解决方案!jquery大气跨域限制
这是在给定的示例页面中使用的远程域的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);
});
感谢
谢谢,我从来没有碰过node.js。你能否给我一个例子说明它将如何实施?谢谢! – Alex
+1表示node.js。 Nginx作为一个简单的代理服务器也非常简单。 – tjameson
我在服务器上使用nginx,也许它会是最好的方法;你能给我一个它如何工作的例子吗?谢谢 – Alex