The code is as follows: I wrote a method to query the results, but the debug process found that the result set has data, how can I get through the variable?
JScript Code
Copy Code code 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);
I get the result is undefined result, but the method is comfortable return the result, please enlighten me.
HTML Code
Copy Code code as follows:
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",//using the Get method to access the background
DataType: "JSON",//Return data in JSON format
URL: "Accountlist.action",//background address to access
data:data,//the data to be sent
Complete:function () {},//ajax hide loading prompt upon completion of request
Success:callbackfun//msg for the returned data, here do the data binding
});
}
function Callbackfun (msg) {
$ ("#totalCount"). HTML (msg.totalcount);
$ ("#page"). 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= ' MMTD ' ></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"). 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 that binds the data
Row.appendto ("#datas");//Add to Template's container
});
}
JScript Code
Copy Code code 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 is the callback function to return the data instead of the function you defined, which is modified 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;
}