Not sure of the right way of calling multiple functions. I just need simple syntax help
New to jQuery. Need help with simple syntax.
<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"开发者_JAVA技巧).each(function () {
$("#output").append($(this).find("successCode") + "<br />");
$("#output").append($(this).find("errormessage") + "<br />");
});
}
});
});
</script>
I got a validation form plugin and a ajax form plugin. Please what is the right way to call them. cause the way i have them now ajax doesn't seem to work.
Thank you
if you want to call ajax method after form validation you can done like this
$("#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 />");
});
}
});
}
.validate() returns validator not form object. Try calling .ajaxForm() first then .validate().
精彩评论