我正在创建验证脚本和ajax调用。我面临的问题是
警报消息在条件中不起作用
我不知道发生了什么,当我运行脚本时,在Chrome中显示:
Uncaught SyntaxError: Unexpected identifier
下面是我的代码:
$("#myCA-Form").validate({
rules:{
field1:"required",
city:"required",
email:{
required:true,
email:true
},
phone:{
required:true,
number: true,
minlength:9,
maxlength:10
}
},
messages:{
name:"Please enter your username..!",
email:"Please enter your email..!",
phone:"Enter your mobile no"
},
submitHandler: function(form) {
var formData = $(form).serialize();
var id = $('#product_id2').val();
var name = $('#field1').val();
$.ajax({
url: "https://eaxmple.co.in/test.aspx?"+formData,
type: "POST",
cache: false,
dataType: "jsonp",
crossDomain: true,
data: {formd : formData },
success: function(data) {
}
});
if(id=='100105')
{
alert("sdfsd");
document.getElementById("msg").innerHTML='submit Successfully!!!';
}
}
});
答案 0 :(得分:0)
您的代码没有问题。它的工作完美。我希望问题出在其他地方
这是代码的精确副本,带有添加的HTML代码
$("#myCA-Form").validate({
rules:{
field1:"required",
city:"required",
email:{
required:true,
email:true
},
phone:{
required:true,
number: true,
minlength:9,
maxlength:10
}
},
messages:{
name:"Please enter your username..!",
email:"Please enter your email..!",
phone:"Enter your mobile no"
},
submitHandler: function(form) {
var formData = $(form).serialize();
var id = $('#product_id2').val();
var name = $('#field1').val();
$.ajax({
url: "https://eaxmple.co.in/test.aspx?"+formData,
type: "POST",
cache: false,
dataType: "jsonp",
crossDomain: true,
data: {formd : formData },
success: function(data) {
}
});
if(id=='11')
{
alert("sdfsd");
document.getElementById("msg").innerHTML='submit Successfully!!!';
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<form id="myCA-Form">
<input name="field1" type="text"/>
<input name="city" type="text"/>
<input name="email" type="text"/>
<input name="phone" type="text"/>
<input value="11" id="product_id2" type="hidden"/>
<button class="save-post">Save Post</button>
</form>
答案 1 :(得分:0)
您不应将表单数据附加到URL,如果您想要类似的东西,则应查看GET方法而不是POST。您可能想了解有关POST和GET的更多信息。