在下面的代码中,当我alert
在调用 ajax 之前,它按预期执行并回显出正确的信息;但是,当我尝试通过 php 传递信息时,数据似乎是空的。我在我的 php 中做错了什么?
Javascript:
$('#submit_fourth').click(function(){
//send information to server
var email = $('input#email').val();
var hash = $('input#username').val();
var type = $('input#type').val();
var finish = "email=" + email + "hash=" + hash + "type=" + type;
alert(finish);
$.ajax({
cache: false,
type: 'POST',
url: 'process.php',
data: finish,
success: function(response) {
alert('it worked!');
}
});
});
PHP:
<?php
$to = 'blanet910@yahoo.com';
$subject = 'Hash testing requested';
$message = $_POST['finish'];
$headers = 'From: webmaster@hashtester.com' . "\r\n" .
'Reply-To: webmaster@hashtester.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>