Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Return value undefined from $.post


shingokko - 5:51 am on Apr 22, 2012 (gmt 0)


OK, the problem is that the callback function of the AJAX call is inside valAgainstDataBase thus the value returned from the function is not used. I think it would work if you change it to:

function valAgainstDataBase(callback) {
$.post("ajax_works_v2.php", { username: $('[id=username]').val(), password: $('[id=password]').val()}, callback);
}

function chestLoginForm() {
valAgainstDataBase(function(data) {
alert('return value: ' + data);
});
}


Hope this works!


Thread source:: http://www.webmasterworld.com/javascript/4443875.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com