Thanks a lot, Beres & James. On Tue, Feb 17, 2009 at 9:01 AM, Beres Botond <boton...@gmail.com> wrote:
> > Basically the main point of what James said is that you don't send the > request at all in the first place *instantly*.. only after > a small delay, so if the user keeps typing only one request will be > sent (the latest one) > > I assume you have a keyup event on the search input or similar... > trying to keep it as simple as possible: > > // global variables on top of your onload.js (or similar) > var t = 0 > var tdelta = 500 // ms - adjust as you like > // > > > $('mysearchinput').keyup(function()) { > if(t) { > clearTimeout(t) > } > > t = setTimeout(do_request, tdelta); > } > > > // lets put this into a function (it's just more simple to work with > setTimeout) > function do_request() { > > var inputString = $('mysearchinput').val() > > if(inputString.length == 0) { > // Hide the suggestion box. > $('#suggestions').hide(); > } else { > > var request = $.post("AJAXModule.php", { > queryString: ""+inputString+""}, > function(data){ > if(data.length >0) { > > console.log(data); > > } > }); > } > } > > > > > > On Feb 15, 11:50 pm, Chintan Tank <tankchin...@gmail.com> wrote: > > Thanx James for the reply. I am kind of a greenhorn in using > > Javascript/Jquery. I ddnt follow you exactly. This is the snippet of the > > code am talking about ... > > > > if(inputString.length == 0) { > > // Hide the suggestion box. > > $('#suggestions').hide();} else { > > > > var request = $.post("AJAXModule.php", { > > queryString: ""+inputString+""}, > > function(data){ > > if(data.length >0) { > > > > console.log(data); > > > > } > > }); > > } > > > > Also I want to make sure that the most current request is satisfied and > not > > anything older than the current. Can you help me with that? > > > > ~ Chintan > > > > > > > > On Sun, Feb 15, 2009 at 3:20 PM, James <james.gp....@gmail.com> wrote: > > > > > Usually auto-complete features implement a request delay (using > > > setTimeout), for example 300ms, before initiating the request. If a > > > user types a character, the setTimeout goes, and if the user types > > > another character within that timeout, it'll clear that timeout > > > (clearTimeout) so the request will not be executed until another > > > 300ms. > > > > > On Feb 15, 7:28 am, Chintan Tank <tankchin...@gmail.com> wrote: > > > > Hi, > > > > I am using the jquery + $.post to create an auto-suggest feature. I > > > wanted > > > > to know if there is a way to cancel previous post requests. > > > > For example this is how it is happening now.. > > > > > > User types in "*jquery*" > > > > > > so my app sends request for *j, jq, jqu, jque, jquer, jquery* .... > > > > and depending on which request is satisfied first it displays the > result. > > > > i want that once the user types in *"jqu"* the app should abort the > > > request > > > > for "*jq*". > > > > is that possible? that would be great help.. solving both > inconsitency & > > > > time issue. > > > > > > -- > > > > Regards, > > > > > > Chintan D. Tank > > > > Graduate Student > > > > Department of Computer Science > > > > Indiana University, Bloomington. > > > > > >http://www.cs.indiana.edu/~cdtank/<http://www.cs.indiana.edu/%7Ecdtank/> > <http://www.cs.indiana.edu/%7Ecdtank/> -- Regards, Chintan D. Tank Graduate Student Department of Computer Science Indiana University, Bloomington. http://www.cs.indiana.edu/~cdtank/