【发布时间】:2011-01-30 21:47:22
【问题描述】:
我正在为 cometd 服务器编写 jquery 客户端(我正在使用 jquery.cometd.js 插件),但我想不出为什么最简单的情况不起作用。
cometd 服务器在 apache 后面(所以它在同一个域上运行)并且所有 请求从 uri http://wwwhost/cometd 转发。
问题是当我尝试连接(通过执行握手())到 cometd 时,它没有发送请求 直接到 /cometd 但到 /cometd/handshake 会出现 404 错误。 我检查了我正在测试的其他应用程序,dojo 总是连接到 /cometd,然后发送消息“握手”。
有人知道 jquery.cometd 为什么要这样做吗?
这是我在 apache 日志中可以看到的:
- - [23/Mar/2010:17:59:30 +0100] "POST /cometd/handshake HTTP/1.1" 404 158 "http://wwwhost/" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100308 Iceweasel/3.5.8 (like Firefox/3.5.8)"
您可以在下面找到我正在使用的代码(它或多或少是我从示例中得到的)。
(function($)
{
var COMETD_URL = "http://wwwhost/cometd";
var cometd = $.cometd;
$(document).ready(function() {
cometd.configure({
url: COMETD_URL,
logLevel: 'debug'
});
cometd.handshake();
});
})(jQuery);
和萤火虫调试:
Initial transport is Object {}
cometd.js (line 278)
Status disconnected -> handshaking
cometd.js (line 278)
Handshake sent Object { version="1.0", more...}
cometd.js (line 278)
Send Object { url="http://wwwhost/cometd/handshake", more...}
cometd.js (line 278)
POST http://wwwhost/cometd/handshake
POST http://wwwhost/cometd/handshake
404 Not Found 104ms
编辑
看起来我的服务器实现不支持非 cometd 的 URI。 Jquery 在末尾添加消息的类型,因此在发送握手时将其发送到: /cometd/handshake 通常看起来像 /cometd/message_type。
我在 cometd.js 代码中找到了发送消息的函数,该函数有三个参数:
function _send(messages, longpoll, extraPath)
这个函数被调用例如:
_send([message], true, 'connect');
这意味着我将始终以 /cometd/handshake 结尾。 我必须修复服务器或注释掉 cometd.js 中的附加 url。
【问题讨论】:
标签: jquery http-status-code-404 comet cometd