I have used a simple AJAX call in a webpage.
he webpage is like this. On clicking the submit button the JavaScript sends the data in a text box to server and displays the response in a div.
My AJAX code is:
var xmlHttp = null;
var api="getdetails.jsp?id=";
var theUrl=api.concat(theId);
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send();
document.getElementById("details").innerHTML=xmlHttp.responseText;
But the problem is that while waiting for the AJAX response the webpage becomes inactive. That is, the user cannot type in text box or click any other link or so. Nothing can be done till the response is received.
How can I make the webpage to be functional while waiting for the response? Do I have to employ multi-threading or any other way?
You need to make your ajax request asynchronous, by setting the
xmlhttp.open("GET",theUrl,true);third parameter in your request as true.
Also this line
document.getElementById("details").innerHTML=xmlHttp.responseText;Should be written with
so that when a state change happens and the result is available in responseText then only u can set a dom element. Please read the documentation of using ajax carefully.
See this example http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first