使用PHP的Ajax调用

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!

This is a jQuery code

$(document).ready(function(e){
        var u=$('#org_name').val();
        $.post("ajax_calls.php",{q:u},function(data,message,xhr){
                                if(message==='success'){
                                    $('#main').text(data);
                                }
                            });

    });

The problem in your code is:

you didn't declared xhttp add this code :

var xhttp = new XMLHttpRequest();