开发者

JQuery UI Autosuggest not displaying items immediately

JQuery sends request and I see the response (via Firebug) with NO ERRORS. But for one or two characters the results are not being displayed in the drop down. Usually on the second character typed the results start showing (and I am typing slowly, 1 character per second or so, just to test if it was a speed issue of some sort).

Here is an example of the req/resp from firebug, at this point the items are not being displayed on the page:

{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "fl":"title,count",
      "sort":"count desc",
      "indent":"on",
      "start":"0",
      "q":"\"b\" AND count:[3 TO *]",
      "wt":"json",
      "rows":"5",
      "version":"2.2"}},
  "response":{"numFound":6536,"start":0,"docs":[
      {
        "title":"blood",
        "count":19890},
      {
        "title":"biochemistry",
        "count":14480},
      {
        "title":"biochemical and biophysical research communications",
        "count":6976},
      {
        "title":"businessweek",
        "count":6498},
      {
        "title":"biochimica et biophysica acta",
   开发者_JAVA技巧     "count":6226}]
  }}

Again, as I said, the console shows no errors on page.

Any thoughts as to how I should pursue this issue?

The Javascript code is:

function autosuggest(term, wid)
{
    var query = "q=" + escape(term);
    var url = "/autosuggest.do?" + query;

    $.getJSON(url, function(terms)
    {
        // iterate over terms

        var list = new Array();

        if (terms.response != null && terms.response.docs != null) {
            for(var i=0; i < terms.response.docs.length; i++)
            {
                var trm = terms.response.docs[i];
                list[i] = trm.title;
            }
            $( '#' + wid ).autocomplete({source: list, select: function(event, ui) { 
                doSuggestedSearch(ui.item.value);
            }});
        }
    });
}

Any thoughts would be appreciated.


autosuggest has a delay option, defaulted to 300ms, which you can override:

$( ".selector" ).autocomplete({ delay: 0 });


Well, it seems to be working fine in this example: http://jsfiddle.net/william/Z7bcQ/

Was there any concurrent requests or heavy processing? I suggest you to somehow profile your page and find the bottleneck. Firebug has a profiler in the console tab. Safari also comes with a nice profiler in its Web Inspector.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜