Hello, I am making Google like suggest and i need help with prototype ajax API. I have text field, where is onkeyup event, which making request that fetch data I need. If someone write fast and type for example word "prototype", js function make several Ajax requests for every single char. How to make prototype to use only one request and if i make new request, old will be "deleted/canceled", so It will stop fetch old data, but new one from field? Uff i hope you will understand :D Thx Code example: new Ajax.Request(url, { onComplete: function(suggest_request) { // inserting data into div etc. etc.. }); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I built a suggestion list, but I simply call the search function on a timer instead of a keystroke. Start the function when the textbox gets focus and kill the timer when someone clicks a suggestion or moves off the control. This way you are not tied to keystrokes. On Dec 17, 12:06 pm, reflex <reflexa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I am making Google like suggest and i need help with prototype ajax > API. > > I have text field, where is onkeyup event, which making request that > fetch data I need. If someone write fast and type for example word > "prototype", js function make several Ajax requests for every single > char. > > How to make prototype to use only one request and if i make new > request, old will be "deleted/canceled", so It will stop fetch old > data, but new one from field? > > Uff i hope you will understand :D > > Thx > > Code example: > > new Ajax.Request(url, { > onComplete: function(suggest_request) { > // inserting data into div etc. etc.. > > });--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
You could try using the Scriptaculous Form.Element.DelayedObserver which will wait a specified time before calling any Ajax Requests. If you really wanted to play it safe, you could also add an if (Ajax.activeRequestCount == 0) before the Ajax.Request to ensure you don''t call multiple requests at the same time. new Form.Element.DelayedObserver (''search_field'', 0.2, function() { if(Ajax.activeRequestCount == 0) { new Ajax.Request(.....); }; }); I''ve kinda been doing it that way, but if there are better ways I''d love to see some examples :) On Dec 18, 4:06 am, reflex <reflexa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have text field, where is onkeyup event, which making request that > fetch data I need. If someone write fast and type for example word > "prototype", js function make several Ajax requests for every single > char. > > How to make prototype to use only one request and if i make new > request, old will be "deleted/canceled", so It will stop fetch old > data, but new one from field? > > Thx--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---