I'm building a page with multiple ajax requests, some are triggered by user interaction and some are set with a JavaScript timer control.
I'm using a basic AJAX script taken from w3school's website but modified to my needs obviously.
The issue I have is when multiple requests are sent at the same time I get the wrong response in the wrong place, for example I might get the JavaScript AJAX response when a user is interacting with a form which also uses AJAX to populate data.
How can I get around this?
http://www.w3schools.com/ajax/ajax_aspphp.asp
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethint.asp?q="+str,true);
xmlhttp.send();
}