function addrewarddb()
{
var rval="98";
$.post("db/mkreward.php",{
proid:getURLParameter("id")
},function(data){
rval="99";
alert(rval);
});
alert(rval);
return rval;
}
when this function executes the function returns 98 instead of 99.the two alerts showing 98,then 99.how to make my function returns 99.i think the problem here is the function returnig before the response from the server page mkreward.php.how i can make the function return after the response from server
The $.post call is asynchronous.
This means that the function returns before the HTTP request has been completed.
Then, when the $.post() call finishes, it then updates the variable and alerts 99.
From the jquery docs: