$.post() asynchronous return value problem
Hi,
I am having problems with my $.post function returning a undefined value. I read somewhere this is because the function returns the value before it gets a result 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);
- }
The returnVal is undefined...
Any help?
Thanks,
Cheers