gpt4 book ai didi

jQuery .ajax 提交在 IE 和 Chrome 中不起作用

转载 作者:行者123 更新时间:2023-12-01 06:07:22 26 4
gpt4 key购买 nike

在我的任何页面上,例如 this one当您单击左侧列的“有问题”按钮时,将通过 jQuery 工具覆盖层显示一个表单。您填写表单,它会提交到 PHP 脚本(本地脚本),如果它验证并提交,您会收到感谢消息或错误消息,具体取决于服务器的响应。在 FF、safari 和 Opera 中运行良好,但在 IE 或 Chrome 中运行不佳。 IE 和 Chrome 只需在空白页面上打印 .ajax 寻找的返回消息以及脚本 URL。我一定有什么不正确的地方,因为即使我的跨域 cURL ajax 脚本也可以工作,但这个不行!这是代码

$(document).click(function() {
$.validator.methods.equal = function(value, element, param) {
return value == param;
};
var validator = $("#request").bind("invalid-form.validate", function() {
$("#summary").html("Your form contains " + validator.numberOfInvalids() + " error(s), please fix.");
}).validate({
//debug: true,
errorElement: "em",
errorContainer: $("#summary"),
errorPlacement: function(error, element) {
error.appendTo( element.parent("li"));
},
success: function(label) {
label.text("ok!").addClass("success");
},
submitHandler: function(form) {
$("#processing").show();
var dataString = $(form).serialize();
$.ajax({
type: $("#request").attr('method'),
url: form.action,
data: dataString,
clearForm: true,
success: function(data) {
if (data=="SuccessMail Sent") {
$("#formWrap, #supportHdln").hide();
$("#thankYou").html('<h2><span>Thank You</span> We have received your request.</h2><p>A Customer Service Representative from NinjaTrader will contact you shortly.</p>').fadeIn("slow");
} else {
$("#formWrap, #supportHdln").hide();
$("#error").html('<h2><span>Uh Oh</span> We are unable to process your request.</h2><p>Please make sure all fields were filled out correctly. If you are still having trouble, please <a href=\"mailto:support@ninjatrader.com?subject=Support Email\">email us</a></p>').fadeIn("slow");
}
}
});
return false;

},
rules: {
hs_customer_firstname: {
required: true,
minlength: 2
},
hs_customer_lastname: {
required: true,
minlength: 2
},
hs_customer_email: {
required: true,
email: true
},
confirmEmail: {
required: true,
email: true,
equalTo: "#hs_customer_email"
},
hs_customer_phone: {
required: false,
digits: true
},
hs_category: {
required: true
},
hs_customLargeTextField: {
required: true,
minlength: 20
},
math: {
required: true,
equal: <?php echo $randomNumTotal; ?>
}
},

messages: {
hs_customer_firstname: {
required: "Please Enter Your First Name",
minlength: "Your First Name Must be at Least 2 Characters"
},
hs_customer_lastname: {
required: "Please Enter Your Last Name",
minlength: "Your Last Name Must be at Leaset 2 Characters"
},
hs_customer_email: {
required: "Please enter your email address",
email: "Please enter a valid email address"
},
confirmEmail: {
required: "Please Confirm Your Email Address",
email: "Please Enter a Valid Email Address",
equalTo: "Please Enter the Same Email Address as Above"
},
hs_customer_phone: {
digits: "Numbers only"
},

hs_category: {
required: "Please Select a Category"
},
hs_customLargeTextField: {
required: "Please Leave a Comment",
minlength: "Your comment must be at least 20 characters"
},
math: {
required: "Please Solve the Problem",
equal: "Please Solve the Problem Correctly"
}
}
});
});

这是运行它的小型 PHP 脚本

<?php

if(empty($_POST['hs_customer_firstname']) || empty($_POST['hs_customer_lastname']) ||
empty($_POST['hs_customer_email']) || empty($_POST['hs_category']) ||
empty($_POST['hs_customLargeTextField']) || empty($_POST['math'])) {
echo ('Success');
}

$headers = 'From: webmaster@ninjatrader.com' . "\r\n" .
'Reply-To: webmaster@ninjatrader.com' . "\r\n" .

$firstname = $_POST['hs_customer_firstname'] ;
//more like this

mail( "email@domain.com", "Support Request",
//$_POST fields
"From: $email");
if(mail($firstname, $lastname, $email, $category, $inquiry)) {
echo ('Mail Sent');
} else {
echo ('Error: Mail failed');
}

?>

最佳答案

这与随机数验证有关,IE 和 Chrome 不喜欢 js 代码中的这一点。一旦我摆脱了它,并从覆盖层引入的表单页面中删除了验证,将其作为单独的 JS 文件添加到父页面,它就可以工作了。不知道为什么随机总数不起作用。当我将PHP函数添加到父页面时,它在验证中没有触发JS错误,但是当您正确添加它们时,数字没有验证。哦,好吧,赢了一些,输了一些。

关于jQuery .ajax 提交在 IE 和 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4331188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com