Jquery 和 cometd 的 URL 和 404 错误问题
我正在为 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);
和 firebug 调试:
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。
I'm writing jquery client for cometd server (i'm using jquery.cometd.js plugin) and I'm running out of ideas why the simplest possible case doesn't work.
The cometd server is behind apache (so it's running on this same domain) and all the
requests are forwarded from uri http://wwwhost/cometd.
The problem is that when I try to connect (by executing handshake()) to the cometd it's not sending requests
directly to /cometd but to /cometd/handshake that gives 404 error.
I checked on the other apps that I was testing and dojo is always connecting to /cometd and then sending message 'handshake'.
Anyone has an idea why jquery.cometd is doing that?
This is what i can see in the apache logs:
- - [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)"
Below you can find the code i'm using (it's more or less what i got from examples).
(function($)
{
var COMETD_URL = "http://wwwhost/cometd";
var cometd = $.cometd;
$(document).ready(function() {
cometd.configure({
url: COMETD_URL,
logLevel: 'debug'
});
cometd.handshake();
});
})(jQuery);
and the firebug debug:
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
EDIT
It looks like my server implementation doesn't support the URI that is other than cometd.
Jquery adds at the end the type of the message so when sending handshake it sends it to:
/cometd/handshake which in general looks like that /cometd/message_type.
I found function that is sending messages in the cometd.js code and the function have three paramters:
function _send(messages, longpoll, extraPath)
and this function is called for example:
_send([message], true, 'connect');
which means i will always end up with /cometd/handshake.
I have to either fix the server or comment out the append url in cometd.js.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的事情。它在maven下运行时有效,但不能直接在jetty中运行。
我向我的码头添加了一个名为 contexts/cometd.xml 的文件。这似乎多余,但它对我有用。
I ran into the same thing. It worked when running under maven, but not directly in jetty.
I added a file named contexts/cometd.xml to my jetty. It seems redundant, but it worked for me.
尝试将
appendMessageTypeToURL
设置为 false但正如文档所说,握手失败可能还有另一个原因
Try setting
appendMessageTypeToURL
to falseBut as the documentation says there might be another reason why the handshake fails