Home > Web Front-end > JS Tutorial > body text

How to obtain the JSON result set implementation code returned by JQUERY AJAX_Basic knowledge

WBOY
Release: 2016-05-16 17:46:58
Original
1393 people have browsed it

The code is as follows: I wrote a method to query the results, but during the debugging process I found that the result set has data. How can I get it through variables?
JScript code

Copy code The 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 result I get is undefined result, but the result is returned comfortably in the method, please enlighten me.
HTML code
Copy code The code is 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",//Use the get method to access the background
dataType: "json",//Return data in json format
url: "AccountList.action",//Backend address to be accessed
data: data,//Data to be sent
complete :function (){},//Hide the loading prompt when the AJAX request is completed
success: callbackFun//msg is the returned data, do data binding here
});
}
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=$(""
""
""
""
""
""
""
""
""
""
);
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 ("Delete");
row.find("#operator"). html("");;
row.attr("id","ready" );//Change the id of the row with bound data
row.appendTo("#datas");//Add it to the container of the template
});
}

JScript code
Copy code The 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 is the callback function returning data instead of what you define The function returns, 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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!