jQuery新手。需要简单语法方面的帮助。
<script>
$(document).ready(function () {
jQuery.validator.addMethod("phoneUS", function (phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");
$("#networx_affiliate").validate({
rules: {
service_name: "required"
}
}).ajaxForm({
url: '**********',
target: '#output',
type: 'post',
dataType: 'xml',
success: function processXml(responseXML) {
// 'responseXML' is the XML document returned by the server; we use
// jQuery to extract the content of the message node from the XML doc
$(xml).find("affiliateresponse").each(function () {
$("#output").append($(this).find("successCode") + "<br />");
$("#output").append($(this).find("errormessage") + "<br />");
});
}
});
});
</script>
我有一个验证表单插件和一个ajax表单插件。请告诉我正确的叫法是什么。因为我现在用的方法ajax似乎不起作用。
谢谢
发布于 2011-07-27 14:34:17
如果您想在表单验证后调用ajax方法,可以这样做
$("#networx_affiliate").validate({
submitHandler: function (form) {
CallAjaxMethod();
},
rules: {
service_name: "required"
}
});
function CallAjaxMethod()
{
$.ajax({
url: 'https://api.networx.com',
target: '#output',
type: 'post',
dataType: 'xml',
success: function processXml(responseXML) {
// 'responseXML' is the XML document returned by the server; we use
// jQuery to extract the content of the message node from the XML doc
$(xml).find("affiliateresponse").each(function () {
$("#output").append($(this).find("successCode") + "<br />");
$("#output").append($(this).find("errormessage") + "<br />");
});
}
});
}
发布于 2011-07-27 14:23:42
.validate()返回验证器而不是表单对象。尝试先调用.ajaxForm(),然后再调用.validate()。
https://stackoverflow.com/questions/6839350
复制相似问题