sách gpt4 ăn đã đi

javascript - .ajax 和 .click 不想在简单的联系表单上为我工作

In lại 作者:太空狗 更新时间:2023-10-29 16:40:52 25 4
mua khóa gpt4 giày nike

我正在从一个用框架构建得很糟糕的网站中删除一些 html/css。此联系表适用于使用该框架的站点,但是当我将其剪切并粘贴到它自己的文件集中时,单击提交按钮时没有任何响应。该文件包含多个页眉、页脚和右侧联系表。 header.php 文件有很多不相关的代码和几个 JS 和 CSS 库的重要链接:










页面的主要内容部分有一些静态内容和联系表的内容。联系方式是:

    





textarea{
background: none repeat scroll 0 0 #ecede9;
border: 1px solid #c9cac6;
height: 118px;
padding: 0 2%;
width: 85%;
margin-left: 24px;
}

Javascript:


php 邮件程序脚本:


if(!isset($hasError)) {
$emailTo = 'xyz@abc.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nPhone Number: $phone \n\nSubject: $subject \n\nComments:\n $comments \n\nCurrent page: $currentpage";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>

原始联系表单有效 - 我所做的唯一区别是将“/ajax/website/contact/process”的 URL 替换为“mailer.php”。我试过在 chrome 中使用调试控制台,根据我尝试的时间,它会给我不同的错误。它有时会说 "$("#submitContactForm").click( "是一个无法识别的函数。

尽我所能找出 submitContactForm 与按钮 ID 相匹配,但我不确定它是否正在寻找隐藏在堆栈中更深的东西,这些东西包含在我不想再使用的 phpixie 框架中。

我看过很多联系表单代码的例子,它看起来相当简单——我有几个其他的例子可以正常工作。我需要使这项工作与编写的差不多,而不是重新开始。弄清楚这一点将有助于使类似的表单在没有底层框架的情况下也能工作。

我尽量保持简单,同时尽可能多地重用代码。我还需要处理其他几种形式,我想找出最好的方法来剥离代码中隐藏的任何框架内容。

câu trả lời hay nhất

  • 您要添加两次数据
  • <đầu> 之外的样式标签
  • $.ajax 中的 URL 没有被引用,最终成为一个 undefined variable
  • 无效的 HTML、spans 和 LI 的奇怪组合

它应该是这样的

function hideContactErrors() {
$('#contactFormErrors, #nameErrorShow, #emailErrorShow, #phoneErrorShow, #messageErrorShow').hide();
}

$('#contactUsForm').on('submit', function(e) {
e.preventDefault();
hideContactErrors();

$.ajax({
url : 'mailer.php',
type : 'POST',
dataType : 'json',
data : $(this).serialize()
}).done(function(data) {
if (data.status == "success") {
$(".successHolder").show().delay(2000).hide(1);
$("#name, #email, #phone, #comments, #subject").val("")
} khác {
$("#contactFormErrors").hide();
$("#nameErrorShow").show().find('span').html(function(_, html) {return data.name||html;});
$("#emailErrorShow").show().find('span').html(function(_, html) {return data.email||html;});
$("#phoneErrorShow").show().find('span').html(function(_, html) {return phone.name||html;});
$("#messageErrorShow").show().find('span').html(function(_, html) {return comments.name||html;});
}
});
});

关于javascript - .ajax 和 .click 不想在简单的联系表单上为我工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27935946/

25 4 0
Xem sitemap của VNExpress