I have a code like this
<script type="text/javascript">
function email(){
var myTextField = document.getElementById('email_hidden').value;
//alert(myTextField);
$.ajax({
type: "POST",
url: "sendmail.php",
data: "email_user="+myTextField,
success: function(response){
alert(response);
}
});
}
</script>
My sendmail.php code is like this.
<?php
$to = $_REQUEST['email_user'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Haan Test<haan@gmail.com>\r\n";
$message_body = "Your Details";
$subject = "Check mail";
mail($to, $subject, $message_body, $headers);
echo "success";
?>
and my html looks like this.
<div id="email_hide"><a href="#" onclick="email()" >Send Email</a></div>
I am getting the response in my firebug console as success
but i could not alert the response. I can receive the mail also for the above jquery ajax functionality(sendmail.php)
In other words, how to alert the response after ajax call..
I have tried onComplete also. plz help me with this.
My Scenerio is like this:
User page(index1.html) >> Paypal Sandbox (for transaction) >> User page(index2.html)
Here in index2.html, i fetch last transaction details from paypal sandbox with a send mail
at the top right corner, so when user clicks the send mail(anchor tag) the mail should be sent via ajax jquery call.
Thanks
Haan
Try using the shorthand jquery method for post: