I need able or disable a click event depending on the server result. I have the following funcion using jquery:
$("#button").click(function(){
var validated = true;
$.ajax({
url: "/Foo",
type: "POST",
success:function(data){
// alert(validated); ----> true
if(data){
validated = false;
// alert(validated); ----> false
}
}
});
// alert(validated); ----> true
return validated;
});
In the above code, always return true. I think the problem is that I set wrong the global variable validated
. I have read this post and this but does not work for me. What am I doing wrong?