C# IHttphandler 上 jQuery 自动完成的随机排序请求
我有一个自动完成文本框,通过用 C# 编写的 IIS7 请求 IHttphandler。
但到达网络服务器的请求似乎是无序到达的。
这是我在输入“guidolin”后从 IHttpHandler 获得的日志示例
406302 2010-11-24 12:33:58,448 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guidoli RequestTime:24/11/2010 12:33:58(396)
406418 2010-11-24 12:33:58,564 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guidolin RequestTime:24/11/2010 12:33:58(507)
407751 2010-11-24 12:33:59,897 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:gu RequestTime:24/11/2010 12:33:58(685)
408008 2010-11-24 12:34:00,154 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guid RequestTime:24/11/2010 12:34:00(56)
408167 2010-11-24 12:34:00,313 [8000] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guido RequestTime:24/11/2010 12:34:00(244)
408562 2010-11-24 12:34:00,708 [5912] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:gui RequestTime:24/11/2010 12:34:00(368)
408832 2010-11-24 12:34:00,978 [8000] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guidol RequestTime:24/11/2010 12:34:00(946)
,显然,请求未按正确的顺序到达。有人已经遇到过这个问题吗?或者有人知道解决方法吗?
下面是自动完成的 jQuery 代码:
textBox.autocomplete({
source: textBox.attr("data-handler-url"),
select: function (event, ui) {
textBox.next("input[type='hidden']").val(ui.item.objectId);
textBox.data('selected-value', ui.item.value);
}
});
I've got a autocomplete textbox requesting an IHttphandler via IIS7 written in C#.
But the requests that get to the webserver seems to arrive unorder.
Here is an example of the log I get from the IHttpHandler after typing 'guidolin'
406302 2010-11-24 12:33:58,448 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guidoli RequestTime:24/11/2010 12:33:58(396)
406418 2010-11-24 12:33:58,564 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guidolin RequestTime:24/11/2010 12:33:58(507)
407751 2010-11-24 12:33:59,897 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:gu RequestTime:24/11/2010 12:33:58(685)
408008 2010-11-24 12:34:00,154 [8256] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guid RequestTime:24/11/2010 12:34:00(56)
408167 2010-11-24 12:34:00,313 [8000] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guido RequestTime:24/11/2010 12:34:00(244)
408562 2010-11-24 12:34:00,708 [5912] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:gui RequestTime:24/11/2010 12:34:00(368)
408832 2010-11-24 12:34:00,978 [8000] DEBUG Services.jQueryHandler - VALID jQueryHandler request data:guidol RequestTime:24/11/2010 12:34:00(946)
So obviously, the request doesn't arrive in the right order. Did any one already face this problem or does someone know a workaround about it ?
Here is the jQuery code for the autocomplete:
textBox.autocomplete({
source: textBox.attr("data-handler-url"),
select: function (event, ui) {
textBox.next("input[type='hidden']").val(ui.item.objectId);
textBox.data('selected-value', ui.item.value);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是 HTTP,根据定义是无状态协议。 HTTP 中没有“顺序”的概念;一切都从请求消息开始。您不能以预期或要求请求具有任何逻辑顺序的方式编写应用程序;毕竟,是客户端选择发送请求。只有它们到达的物理顺序才重要。
在您的示例中,谁敢说客户端没有输入
guidolin
,然后将其更改为gu
?要回答您的问题,此问题没有解决方法,因为它不是问题。如果可能的话,对您的应用程序进行编程,使其不关心这些消息到达的“顺序”。
This is HTTP, by definition a stateless protocol. There is no concept of "order" in HTTP; everything starts with a request message. You cannot code your application in such a way as to expect or require that requests have any kind of logical order; after all, it is the clients that are choosing to send the requests. Only the physical order in which they arrive matters.
In your example, who's to say the client didn't type
guidolin
, then change it togu
?To answer your question, there is no workaround for this issue because it is a non-issue. Program your application so that it doesn't care about the "order" in which these messages arrive, if possible.