Avoiding 'async: false' in JQuery validation
ajax, jquery, jquery-validate
Solution
Use the remote method of jquery validate - if you return true or false you get the default error message and the the field is marked as valid/invalid.
If you return any other string like "this is my error message" the error message displayed will be the string you return.
If the docs say otherwise they are out of date I am using jquery validate 1.10.0
Problem
I've written a JQuery validation method for checking a custom field. To check the data I call a server-side script using AJAX, which in turn, returns true or false. If false, the response will also contain an error message: ``` var errorMessage; var rtErrorMessage = function() { return 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; } } }); return valid; }, rtErrorMessage); ``` This works, however turning of synchronicity means that the browser freezes during the request. This is rather annoying and JQuery even recommend against it... but what is the alternative? Thanks in advance.