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!
If the browser is interfering with your AJAX-y autocomplete, try setting
autocomplete="off"on the input element.