I am using additional method for checking capcha validation using jquery.validate
$.validator.addMethod("ajax_validation", function(value) {
var ajax_data='ajax_mode=capcha_validation&code='+value;
$.ajax({
type: "POST",
url: "/app/ajax_validation/",
data: ajax_data,
dataType: "text",
success: function(msg){
if(msg=='true')
{
alert('true');
return true;
}
else
{
alert('false');
return false;
}
}
});
}, 'Please enter code correctly!');
Even when i retain true value error is always displayed on screen how to handle this.
If you want to catch the result and go any further, you need to call jquery ajax in sync format. In your code, whatever the result is, the default behavior (which should be an error message, I think) happens.
Don’t forget that jQuery Ajax call are Async by default (“A” from “Async” is Asynchronous) and if you want to do ajax call in sync manner, you need to do turn it to ‘false’ like this:
(I put your method in a separate function for clarity)
However, note that ajax Sync calls may freeze the browser and generally is not a good practice.