I am trying to call a function inside a click event with jQuery, but jQuery returns undefined when the function is called. What is the correct way to do this?
$(document).ready(function() {
$('#my_button').click(function() {
var valid = check(something);
if (valid) { // do something }
});
check = function(param) {
.ajax {
// ajax params
success: function(data) {
if (data)
return true;
}
}
}
});
if you do a console.log(valid), it is returned as undefined
UPDATE: I've added the code inside check(), which is an ajax call. That seems to be the problem. If I just do an alert() inside check, then everything works. So what's wrong with the ajax call?