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


neophyte - 5:17 am on Apr 22, 2012 (gmt 0)


Hello All -

While I've been coding php for years, I'm a real noob at javascript/jquery and have been beating my head over this single function for almost 2 days.

I've cobbled together the valAgainstDataBase() function (shown below) from an example found online. All I need is a return value of TRUE OR FALSE which is echoed from ajax_works_v2.php.

However, all that I get is from my calling function is "undefined"

Here's the calling function:
function checkLoginForm()
{
var logn = valAgainstDataBase();
alert('return value: ' + logn);
}

Here's the function BEING CALLED that should return TRUE or FALSE:

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

The .php file is echoing correctly so I know the issue lies somewhere in valAgainstDataBase().

Can someone please show me the error of my ways?

Great appreciation to everyone in advance.


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