The Code is as follows: I wrote a method to query the results. However, I found that the result set contains data during the debug process. How can I obtain the data through variables?
JScript code
Copy codeThe Code is as follows: function getChildNodeArrayByParentID (categoryCode ){
$. Ajax (
{
Type: "get ",
Url: "DynamicMenuItemsHandler. ashx ",
Data: {MenuItemCode: categoryCode },
Async: false,
Success: function (data ){
Return data;
}
});
}
Var jsonArray = getChildNodeArrayByParentID (01 );
Var jsonArray = getChildNodeArrayByParentID (01 );
The undefined result is obtained in this way, but it is comfortable to return the result in the method. Please kindly advise.
HTML code Copy codeCode: function searchStu (page) {// AJAX query by page
Var xm = $ ("# xm"). val ();
Var xs = $ ("# xy"). val ();
Var data = "cus. xm =" + xm + "& cus. xs =" + xs + "& page =" + page;
$. Ajax ({
Type: "post", // use the get method to access the background
DataType: "json", // return data in json format
Url: "AccountList. action", // The background address to be accessed
Data: data, // The data to be sent
Complete: function () {}, // hide the loading prompt when the AJAX request is complete
Success: callbackFun // msg is the returned data. Bind The data here.
});
}
Function callbackFun (msg ){
$ ("# TotalCount" ).html (msg. totalCount );
$ ("# Page" cmd.html (msg. page );
$ ("# TotalPage" ).html (msg. totalPage );
Var data = msg. list;
Var node = document. getElementById ("datas ");
RemoveChildrenRecursively (node );
Var xy = $ ("# xy"). find ("option: selected"). text ();
$. Each (data, function (I, n ){
Var row = $ ("<tr id = 'template' align = 'center'>" +
"<Td id = 'xmtd'> </td>" +
"<Td id = 'xstd '> </td>" +
"<Td id = 'dhtd'> </td>" +
"<Td id = 'actd '> </td>" +
"<Td id = 'mmt'> </td>" +
"<Td id = 'lxtd '> </td>" +
"<Td id = 'bjtd '> </td>" +
"<Td id = 'sctd '> </td>" +
"<Td id = 'operator'> </td> </tr>"
);
Row. find ("# xmtd"). text (n. xm );
Row. find ("# xstd"). text (xy );
Row. find ("# dhtd"). text (n. dh );
Row. find ("# actd"). text (n. ac );
Row. find ("# mmtd"). text (n. mm );
Row. find ("# lxtd"). text (n. lx );
Row. find ("# bjtd"). text ("edit ");
Row. find ("# sctd" pai.html ("<a href = '.../DelAccount. action? Id = '"+ n. id +"> Delete </a> ");
Row. find ("# operator" ).html ("<input type = 'checkbox' id = '" + n. xh + "'value = '" + n. xh + "'/> ");;
Row. attr ("id", "ready"); // change the id of the row bound to the data.
Row. appendTo ("# datas"); // Add it to the template container
});
}
JScript code Copy codeThe Code is as follows: function getChildNodeArrayByParentID (categoryCode ){
Var result = "";
$. Ajax (
{
Type: "get ",
Url: "DynamicMenuItemsHandler. ashx ",
Data: {MenuItemCode: categoryCode },
Async: false,
Success: function (data ){
Result = data;
}
});
Return result;
}
Var jsonArray = getChildNodeArrayByParentID (01 );
Success: function (data ){
Return data;
}
Here, the callback function returns data instead of the function you defined. The modification is as follows:
Function getChildNodeArrayByParentID (categoryCode ){
Var result;
$. Ajax (
{
Type: "get ",
Url: "DynamicMenuItemsHandler. ashx ",
Data: {MenuItemCode: categoryCode },
Async: false,
Success: function (data ){
Result = data;
}
});
Return result;
}