I am trying to get the below code to call to a PHP file, and show the returned data. In Firefox, the alert shows blank, and in IE it shows sometimes but mostly nothing. The PHP script is a simple echo "hello";
.
The script
function make_request()
{
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
function check_login(username, password)
{
var httpRequest;
make_request()
var parameters = 'username=' + username.value + '&password=' + password.value;
httpxml.onreadystatechange = stateck;
httpxml.open('POST', 'login.php', true);
httpxml.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
httpxml.setRequestHeader('Content-Length', parameters.length);
httpxml.send(parameters);
function stateck()
{
if(httpxml.readyState==4)
{
alert(httpxml.responseText);
}
}
}
The markup
<table class="form" id="form" cellpadding="10" >
<form id="signup_form" name="form" method="post" />
<tr>
<td>Username</td>
<td><input type="text" name="username" id="username" size="26" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" size="26"/></td>
</tr>
<td>
<input type="submit" name="button" id="button" value="Submit" onClick="check_login(username, password);"/>
</td>
</form>
</table>
</div>
Thanks