I have a simple php mailer:
PHP Code:
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$to = "whoever@me.com";
$subject = "Some subject";
$header = "From: $name <$email>";
if($name == "" || $email == ""){
echo "Some reminder to fill in all fields.";
}else{
mail($to, $subject, "$message", $header);
echo "Some success message.";
}
?>
My AJAX jQuery form looks like this:
Code:
$(document).ready(function () {
var name=encodeURIComponent(document.getElementById("name").value);
var email=encodeURIComponent(document.getElementById("email").value);
var message=encodeURIComponent(document.getElementById("message").value);
$("#form").submit(function (event) {
event.preventDefault();
$.ajax({
type: "post",
dataType: "html",
url: 'mail.php',
data: "name="+name+"&email="+email+"&message="+message,
success:function(something){}
});
});
});
Basically, I want the PHP message to return to the page via the success function, but I'm not sure how to make that happen. this code [document.getElementById("results").innerHTML=something.responseText;] returns an "undefined" error. The reason I want this is because most jQuery forms respond with success if the the form has been submitted successfully (i.e., all fields have been correctly filled in), but this does not mean that the PHP has processed successfully. Any help would be appreciated.