当提交需要执行两个操作时,一个简单的弹出式 HTML 表单。 1.将客户信息发送到现有数据库 2. 将客户重定向到感谢页面。
在另一位 Stackoverflow 成员的帮助下,我们能够处理此代码。但是,代码不起作用。我觉得我对代码做了一些非常错误的事情,抱歉无法弄清楚。请帮忙!
目前,表单正在发送到数据库,但重定向到现有的邮件列表注册页面,如果我将操作更改为感谢页面,那么表单将发送到感谢页面,但不会提交到数据库。
我比较喜欢用Jquery,我对PHP不是很熟悉,如果有人能指导我,我也可以实现PHP。即使在电子邮件地址输入中没有输入任何内容,表单也会被重定向。有没有办法告诉客户输入有效的电子邮件地址,然后将他带到 Thankyou 页面?谢谢
数据库地址:“http://www.mywebsite.com/MailingList_subscribe.asp” 感谢页面地址:“https://www.mywebsite.com/Articles.asp?ID=252”
HTML 标题
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
$(document).ready(function(){
$('#formId').submit(function(){
$.ajax({
type: "POST",
url: "http://www.mywebsite.com/MailingList_subscribe.asp",
context: document.body
}).success(function() {
location.href = "https://www.mywebsite.com/Articles.asp?ID=252";
});
});
)};
</script>
HTML 主体:
<form name="MailingList" id="formId" method="post" action="http://www.mywebsite.com/MailingList_subscribe.asp">
<input type="text" name="emailaddress" placeholder="Email Address" maxlength="100" size="28"> <br>
<input type="submit" name="Submit" value="Submit" width="260px">
</form>
CSS:
input[type=text] {
padding:1px; border:1px solid #c6c7cc;
box-shadow: inset 0 1px 1px
-webkit-border-radius: 13px;
width: 98%;
font-size:14px;
font-family: Lucida Grande;
font-weight: regular;
margin-left: 2px;
margin-top:10px;
}
input[type=submit] {
background: #9B1C1F;
width: 100%;
font-family: Lucida Grande;
color: #ffffff;
font-weight: bold;
font-size:18px;
text-align:left;
margin-top:10px;
padding:5px 15px;
margin-left:0px;
border:0 none;
cursor:pointer;
display: inline-block;
}
最佳答案
$(document).ready(function(){
$('#formId').submit(function(){
$.ajax({
type: "POST",
url: "http://www.my website.com/MailingList_subscribe.asp",
context: document.body
}).success(function() {
location.replace("https://www.teabeyond.com/Articles.asp?ID=252"); //<=== edit
});
});
)};
并强制用户输入您可以使用的有效电子邮件
<input type=email />
代替
<input type=text />
关于javascript - HTML 表单提交到数据库并重定向到感谢页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25921606/