gpt4 book ai didi

jquery - 错误: When Post using ajax

转载 作者:行者123 更新时间:2023-12-01 03:10:52 25 4
gpt4 key购买 nike

当我单击“注册”按钮时,控制台中显示错误“submit_form 未定义”

我检查了所有内容是否有错误,但没有找到错误所在

请解决我的问题......

这是我的 HTML

<form>
<div class="modal-body" style="color: black;font-weight: bold">
<div class="row">
<div class="col-md-12">
First Name
</div>
</div>
<div class="row">
<div class="col-md-12">
<input id="fname" name="fname" type="text" placeholder="First Name" style="width: 291px;height: 40px;border: 1px solid #dcdcdc" required/>
</div>
</div>
<div class="row">
<div class="col-md-12" style="margin-top: 15px">
Last Name
</div>
</div>
<div class="row">
<div class="col-md-12">
<input id="lname" name="lname" type="text" placeholder="Last Name" style="width: 291px;height: 40px;border: 1px solid #dcdcdc" required/>
</div>
</div>
<div class="row" style="margin-top: 15px">
<div class="col-md-12">
Email Address
</div>
</div>
<div class="row">
<div class="col-md-12">
<input id="email" name="email" type="email" placeholder="Your Email" style="width: 291px;height: 40px;border: 1px solid #dcdcdc" required/>
</div>
</div>
<div class="row" style="margin-top: 15px">
<div class="col-md-12">
Contact Phone
</div>
</div>
<div class="row">
<div class="col-md-12">
<input id="phone" type="text" placeholder="Your Contact" style="width: 291px;height: 40px;border: 1px solid #dcdcdc" required>
</div>
</div>
<div class="row" style="margin-top: 15px">
<div class="col-md-12">
Company Name
</div>
</div>
<div class="row">
<div class="col-md-12">
<input id="company" type="text" placeholder="Company Name" style="width: 291px;height: 40px;border: 1px solid #dcdcdc" required>
</div>
</div>
<div class="row" style="margin-top: 15px">
<div class=" col-md-12">
Account Type
</div>
</div>
<div class="checkbox">
<label><input name="account" class="account" type="radio" value="1">Entrepreneur</label>
</div>
<div class="checkbox">
<label><input name="account" class="account" type="radio" value="2">Executive</label>
</div>
<div class="checkbox">
<label><input name="account" class="account" type="radio" value="3">Corporate</label>
</div>
<div class="row">
<div class=" col-md-12">
Subscription Type
</div>
</div>
<div class="checkbox">
<label><input class="subscription" type="radio" value="1">Monthly Payments</label>
</div>
<div class="checkbox">
<label><input class="subscription" type="radio" value="2">One Time Annually</label>
</div>
<div class="modal-footer" style="margin-top: 20px">
<button type="button" id="mc-embedded-subscribe" class="btn btn-success" onclick="submit_form()">Register</button>
</div>
</div>
</form>

这是我的脚本

function submit_form(){

var fname = jQuery('#fname').val();
var lname = jQuery('#lname').val();
var email = jQuery('#email').val();
var contact = jQuery('#phone').val();
var company = jQuery('#company').val();
var account = jQuery(".account:checked").val();
var subscription = jQuery(".subscription:checked").val();
alert(fname);
alert(lname);
alert(email);
alert(contact);
alert(company);
alert(account);
alert('your subscription='+subscription);
var page_path = "http://ableagenda.com/webapp/admin/register_user.php";
var data_post = "fname="+fname+"&lname="+lname+"&email="+email+"&tel="+contact;
jQuery.ajax({
type : "POST",
data : data_post,
url : page_path,
cache : false,
processData : false,
success function(){
alert('Your Form is Submitted');
}
error:function(xhr, status, error) {
alert('Error');
}

});
// alert(account);


}

最佳答案

成功回调后您错过了一个逗号。

success function(){
alert('Your Form is Submitted');
} // no comma...
error:function(xhr, status, error) {
alert('Error');

不过,这些类型的错误应该在调试器中显示为语法错误。我还建议将来使用 console.log() 而不是 alert(),我不敢相信用所有的东西来测试这个页面有多么困难这些警报出现...

此外,还有像 http://www.jslint.com/ 这样的工具可以帮助您发现这些错误。

关于jquery - 错误: When Post using ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30661588/

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