How to make Ajax request from a drupal page? I have tried to make an Ajax request from drupal page. But output data is not correct . I have tried this

Ajax code:

function searchemail()
{
var email =$('#email').val();
    alert(email);
        $.ajax({
        method: "POST",
        contentType: "application/json; charset=utf-8",
        url: "emailcheck.php",
        data: "email="+"test",
        success: function(ret){
     alert(ret);
        },
        error: function(x,e){
            alert("error occur");
        }
    })

}


Output Code

&lt;?php

echo "test"+$_REQUEST['email'];


But it prints only a 0 instead of 'test'
Have look at jQuery.ajax():

$.ajax({
  method: "POST",
  url: "emailcheck.php",
  data: { email: "test" }
})
.done(function( msg ) {
  alert( "Data Saved: " + msg );
});


Also check your url. Your PHP file has to be in the same folder as your js file when you use relative paths.