How to obtain the implementation code of the JSON result set returned by JQUERY AJAX

Source: Internet
Author: User

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;
}

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.