I am trying to build a simple sign up form using AJAX and PHP. On submitting the form the submit_create_user_form() function is called.
This AJAX function calls ajax_calls.php page.
function submit_create_user_form(){
var u = document.getElementById("org_name").value;
xhttp.onreadystatechange = function(){
if (xhttp.readyState == 4 && xhttp.status == 200) {
var result =xhttp.responseText;
//status.innerHTML=xhttp.responseText;
if(result==="Successful"){
//window.scrollTo(0,0);
document.getElementById('main').innerHTML ="An activation link has been sent to the new user's E-mail ID";
}
else
status.innerHTML="Some error Occurred!!";
}
}
xhttp.open("POST", "ajax_calls.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("q="+u);
}
ajax_calls.php echoes "Successful" which is checked with xhttp.responseText in the above code snippet. Even then the output is "Some error occured."
ajax_calls.php:
if( isset($_POST["q"]) ){
echo "Successful";
}
could someone help with this? Thanks!