I have a function:
function name(type)
{
$.i="";
$.post("name.php", type, function(data, status){
$(".pic").attr("src", data);
$.i=data;
})
alert($.i); //this is not working
}
In the above code the alert is displaying empty alert box. But when i have
function name(type)
{
$.i="";
$.post("name.php", type, function(data, status){
$(".pic").attr("src", data);
$.i=data;
alert($.i); //now this is working
})
}
I want to return the value returned by name.php file . name.php contains echo "string".
It is for testing only. In the second given code string is displaying but in first it is not working.
What can i do to return the value from the function and assign the received value to variable declared outside $.post() or in the function.
Thanks in advance.
The async call back of post is call after the execution of post. You can call a function from post to perform operation on value return in callback.
You can try using deffered execution this post will guid you how to achieve it.