My AJAX call is currently working fine, but the response time is slow. To prevent users from clicking multiple times while waiting for a response, I want to display a message like "Converting please wait" before the data is received. Below is the code that I have implemented:
function postajax()
{
document.getElementById('linksarea').innerHTML = "<img src='images/waiting.gif'> Converting please wait...";
var xmlhttp;
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("links").innerHTML=xmlhttp.responseText;
}
var links = window.document.getElementById('linksarea').value;
xmlhttp.open("POST","ajax.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("links="+links+"&username=xxxx");
}
This is the HTML section where I am making the modifications:
<div id="memberright">
Convert the links here<br />
<textarea name="links" id="linksarea" cols="65" rows="10"></textarea><br />
<input type="button" id="buttonr" onclick="postajax()" value="Convert">
</div>
<div id="ajax">
<div id="links">
</div>
</div>