Monday, 15 April 2013

ajax - Avoiding 'async: false' in JQuery validation -



ajax - Avoiding 'async: false' in JQuery validation -

i've written jquery validation method checking custom field. check info phone call server-side script using ajax, in turn, returns true or false. if false, response contain error message:

var errormessage; var rterrormessage = function() { homecoming errormessage; } jquery.validator.addmethod('customvalidation', function(value, element) { var valid = true; var url = '/validation?data=' + value; $.ajax({ url: url, type: 'get', datatype: 'json', async: false, success: function(responsedata) { if (responsedata && !responsedata.isvalid) { errormessage = responsedata.errormessage; valid = false; } } }); homecoming valid; }, rterrormessage);

this works, turning of synchronicity means browser freezes during request. rather annoying , jquery recommend against it... alternative?

thanks in advance.

use remote method of jquery validate - if homecoming true or false default error message , the field marked valid/invalid.

if homecoming other string "this error message" error message displayed string return.

if docs otherwise out of date using jquery validate 1.10.0

jquery ajax jquery-validate

No comments:

Post a Comment