When I was trying a simple code to test XMLHttpRequest()
function, I used this code:
<script>
//Global variable to store the XMLHttpRequest object
var myRequest;
//Package the request into its own function
function getData()
{
//Feature-testing technique to make sure the browser
//supports the XMLHttpRequest object
if (window.XMLHttpRequest)
{
//create a new instance of the object
myRequest = new XMLHttpRequest();
}
//else - the XMLHttpRequest object is not supported:
//create an instance of ActiveXObject
else
{
myRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
//Use the open(retrievalMethod, "myDataFile.txt", bool) method
myRequest.open("GET", "test.txt", true);
//Use send() with a null argument - we have nothing to send:
myRequest.send(null);
//attach a function to handle onreadystatechange,
//that is, the response from the server:
myRequest.onreadystatechange = getData;
alert(myRequest.responseText);
}
</script>
I want to simply return the contents of my 'test.txt' file.
Now, When I am running this code, I get nothing! I see only a blank screen.....
And now, When i set Asnyc parameter to false, It Works!
Why??