雅虎自动完成结果有时会显示旧查询

发布于 2024-08-06 14:10:20 字数 1299 浏览 2 评论 0原文

我正在使用雅虎自动完成与远程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转身泪倾城 2024-08-13 14:10:20

您已接近 cancelStaleRequests。你想要的是这样的:

oDS.connXhrMode = "ignoreStaleRequests";

You were close with cancelStaleRequests. What you wanted was this:

oDS.connXhrMode = "ignoreStaleRequests";
三寸金莲 2024-08-13 14:10:20

您可以在每个查询上添加一些 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文