<html>
<head>
<script type = "text/javascript">
var request;
function makeRequest(){
request = new XMLHttpRequest();
var user = document.getElementById("email").value;

var url = "subscribe.php?email=" + user;
request.onreadystatechange = onResponse;
request.open("GET",url,true);
request.send(null);
}


function checkReadyState(obj){
	console.log(obj);
if (obj.readyState == 0){
   	document.getElementById("response").innerHTML =  "Sending Request....";
}
if (obj.readyState == 1){
   	document.getElementById("response").innerHTML =  "Loading Request....";
}
if (obj.readyState == 2){
   	document.getElementById("response").innerHTML = "Response Loaded....";
}

if (obj.readyState == 3){
   	document.getElementById("response").innerHTML = "Response Ready....";
}

if (obj.readyState == 4){


	if (obj.status == 200){
		return true;
    }
    else if (obj.status == 404){
   	document.getElementById("response").innerHTML = "Not Found";

    }
    else{
   	document.getElementById("response").innerHTML = "There was a problem";
    }

}

}

function onResponse(){
	console.log("request is " + request);
   if (checkReadyState(request)){
   	document.getElementById("response").innerHTML = request.responseText;
   }
}
</script>
</head>
<body>
  <form action = "subscribe.php" method = "get">
Google Suggest Enter a search term : <input type = "text" name="email" id = "email" onkeyup="makeRequest();">
<input type="submit" name="submit" value="Search">
</form>
<div id = "response"></div>

 </body>
</html>