我真的不明白这里发生了什么。我有一个jquery脚本,它将表单发布数据发送到注册脚本,然后将电子邮件发送给用户注册,并将用户Id返回给调用jquery函数,在那里它被转发到另一个脚本进行处理。
问题:如果我省略了邮件功能,脚本效果很好,但是,将其引入脚本会阻止变量返回到调用jquery函数。有什么想法发生了什么?这是Jquery脚本:
<script>
/* attach a submit handler to the form */
$("#purchaseForm").submit(function(event) {
var intRegex = /^\d+$/;
/* stop form from submitting normally */
event.preventDefault();
$.post("process_signup.php", $("#purchaseForm").serialize(),function(data){
if(intRegex.test(data)){
if(data!=0){
alert(data);
document.getElementById("bag_contents_hidden").value=data;
$.post("process_order.php", $("#bag_contents").serialize(), function(data2){
if(data2){
window.location.replace("?process=100&success=1");
}else{
window.location.replace("?process=100&fail=1");
}
});
}
}
else{ //Not Important, validation stuff
}
});
});
//
PHP
if($oid){
if(mail($email,$title,$message,$headers,'O DeliveryMode=b')){
echo $oid;
unset($_POST['processorder_hidden']);
}else{
echo 0;
}
}
答案 0 :(得分:2)
由于您期望来自post
请求的数据,mail
函数生成的任何错误都会产生问题。
这是解决问题的正确方法
$status = @mail($to, $subject, $content); //suppress the error generated from being passed to the view
//instead handle it later
if($status) {
//handle success
} else {
//handle unsuccess
}