Reputation: 703
I am new to web development and am trying to write simple code that changes visibility of an HTML element using JavaScript and AJAX, but my code is not working.
The PHP script I'm running is simple:
<?php
echo TRUE;
?>
The JavaScript code is:
function getuname() {
//create_xmlhttpobj();
var userName = document.getElementById('uName');
var url = "http://localhost/test.php";
//script that returns whether username exisits or not
request.open("GET", url, true);
request.send(null);
request.onreadystatechange = updatepage();
//alert(userName.value);
}
function updatepage() {
//alert(request.readyState);
alert(request.readyState);
//alert(request.responseText);
if (request.readyState == 4) {
alert('here123');
togvis();
}
}
The statement alert(request.responseText);
shows a blank alert box.
Can someone tell me what I might be doing wrong?
Upvotes: 0
Views: 261
Reputation: 207501
You are calling the function updatepage
, not assigning it.
request.onreadystatechange = updatepage();
needs to be
request.onreadystatechange = updatepage;
Upvotes: 1