当我点击注册按钮时,控制台中会显示错误," 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);
}
答案 0 :(得分:4)
在成功回调后你错过了一个逗号。
success function(){
alert('Your Form is Submitted');
} // no comma...
error:function(xhr, status, error) {
alert('Error');
这些错误应该在调试器中显示为语法错误。我还建议将来使用console.log()
而不是alert()
,我无法相信在显示所有这些警报的情况下测试此页面有多么困难......
此外,像http://www.jslint.com/这样的工具可以帮助您发现这些错误。