English 中文(简体)
停靠
原标题:stop running ajax calls

i have a dynamic search in php with jquery. When i m entering a letter, an ajax call starts. My problem is, that all ajax calls are working till end, so that every letter is a full call. When a user is entering a full word then i have unused requests. How can i stop the unused calls?

非常感谢

最佳回答

利用时间来推迟提出几毫秒的要求,并在出现新的钥匙时加以澄清。

something like

var searchtimeout;
$( #search ).keyup( function(){
  if (searchtimeout)
      {
        clearTimeout(searchtimeout);
      }
  searchtimeout = setTimeout(function(){
                                // initiate the ajax call here..
                             }, 300);
} );
问题回答

用户在完成或可能使用

您可以采取的一种方式是,当用户要求交还钥匙时,或者在等待几秒(1-3)时,发出要求,看用户是否停止打打打打打打打打字,然后提出要求,那么你就不必在输入箱上寻求所有变化。

Why dont you use the autocomplete plugin in jquery.. I am assuming you have handcoded the dynamic lookup.. auto complete takes care of most of these things and it is also configurable as to after how many letters you want to post to the server..it also implements caching.

I have used it in a lot of asp.net projects and it is pretty neat.. docs.jquery.com/Plugins/autocomplete

这里我的解决办法是:

if (searchtimeout)
        {
            clearTimeout(searchtimeout);
        }
        searchtimeout = setTimeout(function(){
            if(x){
                x.abort();
                alert("MACH WEG!");
            }
            x = $.post(url + "ajax.html?nsearch=1&ckey="+SID, {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
                $( #suggestions ).fadeIn(); // Show the suggestions box
                $( #suggestions ).html(data); // Fill the suggestions box
                x = null;
            });
        }, 300);




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签