Can anybody help or guide me into finding out why the following code will not operate as expected (i.e alert the echo from php) and instead alerts the "something negative happened"?
My Javascript code as follows:
window.onload = function(){
var regForm = document.getElementById("register").onsubmit = checkForm;
}
//Let's see if this user already exists
function checkForm(){
alert("You pressed Register!");
var cc = document.getElementById("un3").value;
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
alert("You are using XML HTTP REQUEST");
}else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
alert("YOU ARE USING ACTIVE X OBJECT");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
alert(xmlhttp.responseText);
return false;
}else{
alert("Something negative happened");
}
}
xmlhttp.open("GET","user_exists.php?q="+cc,true);
xmlhttp.send();
}
My php file simplified to get this thing to work:
<?php
$q=$_GET["q"];
echo "something good happened";
?>