Hey guys, maybe the easiest question for you I do not understand the reason why I'm writing ajax The request I received is an unordered list I always received. I only show those list items that currently match the string in the search box. I apply them in class. I remove all those items which do not have any classes. I have been implemented.
And besides, I'm using a jquery highlights plugin to highlight the current string in the search box inside the list. The exact word is highlighted in the search box in the list list.
Everything works fine except for a case. Whenever the input field is removed from its content and then The browser can not stop the script if it is empty. The bug is caused by 100% plugin or in addition to this line: $ ('# searchresults ul li.matched'). Highlight ($ ('ss) .val ()); ... The plugin itself works fine. I am using it all the time The plugin also works for this scenario, just a rare case in this one when the AJAX request is currently removed and the text in the input is set to crash the browser again.
Why can any one think? Maybe it's just a logical problem I have, I'm already checking whether the input is empty or not. So in fact, the hightlight line should also not be removed when the text in the input is removed.
Any thoughts?
The highlight will still be, your AJAX call is async, it runs with the rest of your code.
You check that the input is not empty, then the fire closes its AJAX when it expires, it triggers the rest of the code that you (this code is a callback function) Has passed. You can see the empty string now .
You can try two things. One will be for you to store the string to be searched for, but it can also be an indicator for the following:
function doSearch (keycode) {var input = $ ('s '). Val (); If (input! == '') {jqXHR_Old = $ .post (searchmap.execural, data, function (feedback) {$ sr.html (response); // Add class in all the results that match the current search variable = $ ('# Searchresults ul li: icontains ("' + input + '') '); found.addClass (' match '); // Delete all remaining list items $ (' # searchresults ul li '). Matched '). Remove the current string in the search box $ (' # searchresults ul.matched '). Highlight (input); Optionally wrap the line Try the same logic The reason for the mistake is:
function doSearch (keycode) {if ($ ('s'). Val ()! == '') {jqXHR_Old = $ post (searchmap.execl, Data, Function (Response) {$ sr.html (response); // Match all search results that meet the current search works = $ ('#Searchersults ULT: ICENTS' ('+ $ (' .s' ). Val () + '")); found.addClass (' matched '); // Delete all remaining list item $ (' # searchresults ul li ') No (' Match ') .remove ( ); // if the current highlight string in the search box ($ ('s'). Val ()! == '') {$ ('# searchresults ul li.matched') Highlight ($ ('ss') .val ()); }
Comments
Post a Comment