[英]jQuery Validation not validating
In my ASP.NET Web Application I'm trying to sending data from a User Control using jQuery Ajax call to WebMethod. 在我的ASP.NET Web应用程序中,我试图使用对WebMethod的jQuery Ajax调用从用户控件发送数据。 So within the User Control I'm using HTML controls only. 因此,在用户控件中,我仅使用HTML控件。
Now I need to validate the input data before sending data with Ajax call. 现在,我需要在使用Ajax调用发送数据之前验证输入数据。 I tried using jQuery Validation Plugin but it does not work as Form validity is always true
我尝试使用jQuery Validation Plugin,但由于Form Validity始终为true
因此无法正常工作
HTML: HTML:
<input type="text" id="txtName" name="txtName" class="text-box" />
<button type="button" id="btnSubmitInquiry" class="button" value="Submit">
Submit
</button>
Javascript : Javascript:
$('#btnSubmitInquiry').click(function () {
$('#Form1').validate({
rules: {
txtName: {
required: true
}
}
});
var inquiry = {};
inquiry.Name = $('#txtName').val();
//more fields
var DTO = { 'inquiry': inquiry };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '/Web/Site/AjaxHandler.aspx/Save',
data: JSON.stringify(DTO),
dataType: "json",
success: function (data) {
alert('success');
}
});
});
How to make this work? 如何使这项工作?
Had to add if ($("#Form1").valid())
before Ajax call 必须在Ajax调用之前添加if ($("#Form1").valid())
if ($("#Form1").valid()) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
//....
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.