Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another smart extension to what you are doing, is not to do the ajax call as soon as a key is pressed. If the user types in a long word quickly, you'll get multiple ajax http requests triggered faster than they can return and update your UI.</p> <p>This adds to your server load, and might make the client's UI sluggish.</p> <p>Instead, onkeypress, store all the appropriate details and then call </p> <p>var timeout = setTimeout('some_method()',100);</p> <p>Which says call the some_method() in 100 milliseconds. The first thing you should do within your keypress method is cancel/clear the Timeout call with clearTimeout.</p> <p><a href="http://www.w3schools.com/js/js_timing.asp" rel="nofollow noreferrer">http://www.w3schools.com/js/js_timing.asp</a></p> <p>The some_method() should also clear any timeout, then make the http ajax request.</p> <p>The net effect here is that your ajax request is delayed slightly, but never happens if the user presses another key. Or put another way, don't try and fire an ajx request until the user has stopped/paused typing. 100 milliseconds might be too high or too low, but you hopefully get the idea!</p> <p>You should also take care to deal with a "slow server" situation. Consider this:</p> <ul> <li>User types "hello", pauses for 1 second, you fire an ajax request with "hello" as the parameter</li> <li>User continues to type " world", so the textfield now contains "hello world", and stops typing.</li> <li>You fire a second ajax request with "hello world" as the parameter.</li> <li>The second request (for "hello world") returns first, you update your UI</li> <li>The first request (for "hello") returns, you update your UI again.</li> </ul> <p>Ooops! Have the server include the original query string in the (json) data it returns to the client. When the client gets the ajax data back, check that the result/data is for the query ("hello" / "hello world") that matches what is currently in the text field.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload