$.post() asynchronous return value problem
Hi,
I am having problems with the $.pos() function returning an undefined value. I read somewhere that this is because the function returns the value before it gets a response from the server.
I am not quite sure how to get around this...
- function addMediaCategory(name,parent_id)
- {
- $.post("addMediaCategory.php",{cat_name:name,parent:parent_id},
- function(data)
- {
- if(data == "ok")
- {
- return "ok";
- }
- else
- {
- return "error";
- }
- },"text");
- }
- function callMediaAdd()
- {
- var returnVal = addMediaCategory("Cat1",1);
- alert(returnVal);
- }
returnVal is undefined...
Any help?
Thanks,
Cheers