alpine Posted July 23, 2006 Share Posted July 23, 2006 I have a livesearch in ajax handling queries to a rather big mysql table containing rows of products.What i am experiencing some problems with is that the browser occaitionally freezes (firefox,ie etc - doesn't matter) probably due to problems handling the query results as the customer enters characters in the text field.Now i have set it up so that it's needed at least two chars to actually start searching - but what i think would do things a little easier is to delay each keypress (onkeydown,keypress,keydown) so that the search holds a second or so before sending the http request just to limit the number of queries.I played around with my javascript at first, but the best solution i've come up with so far is to add usleep(500000); on top of the php script handling the db-queries to hold on 0.5 sek before starting.Can anyone point out a better solution than this ??? Quote Link to comment Share on other sites More sharing options...
nogray Posted July 24, 2006 Share Posted July 24, 2006 Actually, live search (with the result showing under the search field) is not usually a good feature. It's resource hog and no one really use it. If you want that feature, I would recommend you set a php file to put the top couple of hundreds search queries in an javascript array, and use that array to show the top searches on key press. This will speed up the list update and won't use a lot of resources. Quote Link to comment Share on other sites More sharing options...
alpine Posted July 25, 2006 Author Share Posted July 25, 2006 Thanks for your thought, i still think i am going to stick with the query on keypress and try and optimize it the best i can as i have near 300.000 rows on products in the db and it seems impossible to find a pattern on most searched items.I think i will try to limit the onkey search to maximum 100 results in standard and make an optional more results button and see if that helps - actually it is working very nice and is actually quite fast too - better and better as i move along and continue fine-tuning it :) Quote Link to comment Share on other sites More sharing options...
alpine Posted July 25, 2006 Author Share Posted July 25, 2006 btw - i use onkeypress in different terms to suit browsers, but what is to be preferred ? - onkeypress or onkeyup ???Javascript is a relative new language to mee so i am in a heavy learning cycle now, getting used to the var instead of $ etc *lol* Quote Link to comment Share on other sites More sharing options...
nogray Posted July 25, 2006 Share Posted July 25, 2006 onkeypress is better since it's supported by most browsers (I think). And you can find out users searches by recording the search terms and how many times. Usually people look for similar products when they visit a site. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.