雅虎自动完成结果有时会显示旧查询
我正在使用雅虎自动完成与远程 php 数据库请求和零时间延迟。问题是有时旧查询的结果会在最近的查询之后返回。
到目前为止,如果我正在搜索初学者,有时如果该查询从服务器返回的时间最长,“beg”的结果将覆盖自动完成下拉列表中的最新结果。
我尝试过中止旧查询,但这会降低用户体验,因为直到最后一次击键才收到服务器请求。
我想知道是否有办法对返回的查询进行排序?确保最近查询的服务器响应显示
提前感谢 大卫
能否在测序方面提供一些帮助?我的雅虎自动完成代码当前如下,我想避免取消过时的请求。
<script type="text/javascript">
YAHOO.example.autocomplete = function() {
// instantiate remote data source
var oDS = new YAHOO.util.XHRDataSource("../employer/post-job/get_towns.php");
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
oDS.responseSchema = {
resultNode: 't',
fields: ['n']
};
oDS.maxCacheEntries = 100;
// oDS.queryMatchSubset = true;
// oDS.connXhrMode = "cancelStaleRequests";
// instantiate YUI autocomplete widgets
var oAC0 = new YAHOO.widget.AutoComplete("input1", "inputcontainer", oDS);
oAC0.minQueryLength = 3;
oAC0.queryDelay = 0.05;
oAC0.maxResultsDisplayed = 10;
return {
oDS: oDS,
oAC0: oAC0
};
}();
</script>
I'm using Yahoo Autocomplete with a remote php database request and zero time delay. The problem is that sometimes the results from an old query come back after the most recent query.
So far example if im searching for beginner, sometimes the results from 'beg' will override the most recent result in the autocomplete dropdown if that query takes the longest to return from the server.
I've tried aborting the old queries but that slows down the user experience as they do not get a server request until the last keystroke.
I was wondering if there is a way to order the queries that return? To make sure that the server response from the most recent query displays
Thanks in advance
David
Any chance of some help on the sequencing? My Yahoo autocomplete code is currently as below, I want to avoid doing the cancel stale requests.
<script type="text/javascript">
YAHOO.example.autocomplete = function() {
// instantiate remote data source
var oDS = new YAHOO.util.XHRDataSource("../employer/post-job/get_towns.php");
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
oDS.responseSchema = {
resultNode: 't',
fields: ['n']
};
oDS.maxCacheEntries = 100;
// oDS.queryMatchSubset = true;
// oDS.connXhrMode = "cancelStaleRequests";
// instantiate YUI autocomplete widgets
var oAC0 = new YAHOO.widget.AutoComplete("input1", "inputcontainer", oDS);
oAC0.minQueryLength = 3;
oAC0.queryDelay = 0.05;
oAC0.maxResultsDisplayed = 10;
return {
oDS: oDS,
oAC0: oAC0
};
}();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已接近
cancelStaleRequests
。你想要的是这样的:You were close with
cancelStaleRequests
. What you wanted was this:您可以在每个查询上添加一些 id,然后将该 id 从服务器重新发送到客户端,并将收到的 id 与当前请求 id 进行比较。
或者也许中止旧查询(如果 API 允许)。
You can add some id on every query then resend that id from the server to the client, and compare that received id to the current request id.
Or perhaps abort old queries, if the API allows you to do so.