Originally, my idea was to take $.post () return function data out of the operation, searched the internet for a long time, said to be the $.post () method to synchronize, and the $.post () returned data assigned to a global variable method.
function GetData (pagecurrent)
{
var result;
$.ajax ({
URL: "/ajax/signmain.ashx",
async:true,//Change to synchronous mode
Type: "POST",
Data: {"pagecurrent": Pagecurrent},
Success:function (data) {
data = eval (' (' + data + ') ');
Result=data;
alert (result);
}
alert (result);
});
}
The first alert outputs the data normally, and the second alert shows the undefined. Many posts say this method can take the return data of $.post () out, but I really do not use it (if you can be useful to guide under the next, greatly appreciated. ), I can only think of him another way.
function GetData (pagecurrent,callback)
{
$.ajax ({
URL: "/ajax/signmain.ashx",
async:true,/
Type: "POST",
Data: {"pagecurrent": Pagecurrent},
Success:function (data) {
data = eval (' (' + data + ') ');
Callback (Pagecurrent,data);
}
});
}
A callback function is called to call the external function in the return function of the $.post (), and when the external function is called, the data is passed as a parameter to the external function, so that the function outside the $.post () is obtained in a disguised way $.post ().
Use $.post () to return the data of a function outside of the $.post () function