A global variable var jsondata;
I have a way to handle Ajax here:
JScript Code:
Copy Code code as follows:
function Getjson (datasourcename) {
$.ajax ({
Type: "Post",
URL: "Ajax/ajaxdata.ashx?" Methodname= "+ DataSourceName,
ContentType: "Application/json;",
Data: "",
DataType: "JSON",
Success:function (Result) {
Jsondata = result;
},
Error:function (Result) {
Alert ("Get information list error");
Window.close ();
}
});
return jsondata;
}
Then I have a class.
JScript Code:
Copy Code code as follows:
function Drawdropdownlist (Sfieldrulemethod)
{
Getjson (Sfieldsourcename);
var B = jsondata;
}
So, why do I always get jsondata when I perform drawdropdownlist?
I interrupted the tracking of the following, found that the Drawdropdownlist method inside all of the implementation will not enter the Getjson method,
Is there any way to bring out the result data obtained in Getjson?
Not in
Copy Code code as follows:
Success:function (Result) {
Do something
},
I just want to get the data out, because Getjson is a common method and does not want to execute a single logic inside.
Can not return in the callback, and need to sync, on it!
Another kind of pass is not recommended synchronization, you need to add a function parameter to my function as a callback function, the results of the AJAX passed to the function, the following code details:
Copy Code code as follows:
function Getjson (datasourcename,callback) {
$.ajax ({
Type: Post)
URL: "Ajax/ajaxdata.ashx?" Methodname= "+ datasourcename,
ContentType:" Application/json; ",
Data:",
DataType: "JSON",
Succe Ss:function (Result) {
Jsondata = result;
Callback (Jsondata)
},
Error:function (result) {
Alert ("Get information list error");
Window.close ();
}
});
//return Jsondata;
}