How to get jquery Ajax returns the JSON result set implementation Code _ basics

Source: Internet
Author: User
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;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.