0

I need some help on a autocomplet function using ajax My problem is : the browser is caching the suggestions from ajax when i press enter on a suggestion, so the next time I'm typing in the suggestion field, i get de value from the cach

Here is the part of the Ajax code through which I send a value to the php code and get the respondsetext

xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","suggest.php?q="+str,true); xmlhttp.send();

and the input tag

input id="valx" onKeyUp="autocomplet(this.value)"

Example: I type in the input field "Htm" and I get the suggestions "Html","HTML CSS" , "HTML XMLS" .... so if I chose "HTML CSS" and press enter, the next time I type "Htm" in the input field the browser shows the cached value => "HTML CSS" an of course I also have my suggestions send by ajax Html","HTML CSS" , "HTML XMLS" ..... I want to get rid of the cached values send by the browser

I saw a tutorial for my problem but I dont know how to apply it to my code because I"m already sending a request through "q". The cod from the tutorial looks like this

xmlhttp.open("GET","demo_get.php?t=" + Math.random(),true); xmlhttp.send(); it is using the random method to send different data request each time ??

Any help would be much appreciated! Thanks!

2 Answers 2

0

If the browser is interfering with your AJAX-y autocomplete, try setting autocomplete="off" on the input element.

2
  • this is the input <input onKeyUp="autocomplet(this.value)" /> how should I set autocomplet="off" in this input. I don't understand your idee
    – soso
    Jun 3, 2011 at 20:39
  • @soso <input autocomplete="off" onKeyUp="autocomplet(this.value)" />
    – Neil
    Jun 3, 2011 at 20:58
0
<input name="myField" .... autocomplete="off" onKeyUp="autocomplet(this.value)">
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.