I'm beginner at javascript so learning constantly very many new things so dont be angry if im asking a really stupid question because still learing the ropes. Trying to implement callback instead async: false. Adding this method to jquery Validator plugin. With async false works fine, but i don't wanna use it. Any help appreciated :)
$.validator.addMethod( "CheckIfUsed",
function(value, element) {
var isSuccess
$.ajax({url :"/x/validate",
data : JSON.stringify({model:$(element).data('model'),
field:element.name,
equals:value}),
contentType : 'application/json',
type : 'POST',
async: true,
success: function(res){
{ isSuccess = res === "true" ? true : false }
}
})
return isSuccess
},"That data allready used");
Tryd this: Javascript callback functions with ajax - did not work
Or am i doing something copletly wrong