gpt4 book ai didi

php - 为什么我的注册表单适用于除 Firefox 之外的所有浏览器?

转载 作者:行者123 更新时间:2023-12-01 02:21:15 25 4
gpt4 key购买 nike

可在此处获取:http://syllableapp.com/test

基本上,在 Safari、Chrome、Opera、Webkit Nightly 等中,该表单工作精美且完全符合预期。但在 Firefox 中,提交时只是......不执行任何操作。这是为什么?

这是我的 JavaScript:

$(document).ready(function() {
$('input[type="submit"]').click(function() {
event.preventDefault();

var email = $.trim($('.email').val());
var emailRegEx = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

if (email == "" || !emailRegEx.test(email)) {
$(this).effect("shake", { times:2 }, 75);
}
else {
var data = "email=" + email;

$.ajax({
type: "POST",
url: "register_email.php",
data: data,
success: function(data) {
if (data == 1) {
$('form').hide();
$('form').html("<p class='success'>You'll be notified! Welcome aboard.</p>");
$('form').fadeIn(300);
}
else {
$('form').hide();
$('form').html("<p class='error'>Dang, there was an error. <a href='mailto:me@christianselig.com'>Email me?</a></p>");
$('form').fadeIn(300);
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error: " + errorThrown);
$('form').hide();
$('form').html("<p class='error'>Dang, there was an error. <a href='mailto:me@christianselig.com'>Email me?</a></p>");
$('form').fadeIn(300);
}
});
}
});
});

还有我的 PHP:

<?php
$db = new mysqli("localhost", "swuclu_emailer", "etreadmill:(", "swuclu_syllable_emails");

if ($db->connect_error) {
echo "0";
}
else {
$email = $_POST["email"];

$stmt = $db->prepare("INSERT INTO emails (email) VALUES (?)");
$stmt->bind_param("s", $email);
$stmt->execute();

echo 1;
}
?>

除了 Firefox 之外的所有浏览器都可以正常运行,到底发生了什么?

最佳答案

使控制台中的错误在页面更改时持续存在。

您将看到此错误:

ReferenceError: event is not defined
http://syllableapp.com/test/scripts/scripts.js
Line 3

这将带您到代码:

$(document).ready(function() {
$('input[type="submit"]').click(function() {
event.preventDefault(); //<--- here

看一下,您会发现该事件未定义。因此出现错误。

因此将变量 event 添加到函数参数列表中

$('input[type="submit"]').click(function(event) { //<-- added variable 

关于php - 为什么我的注册表单适用于除 Firefox 之外的所有浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18302593/

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