Home >
Web Front-end >
JS Tutorial >
How to obtain the JSON result set implementation code returned by JQUERY AJAX_Basic knowledge
How to obtain the JSON result set implementation code returned by JQUERY AJAX_Basic knowledge
WBOY
Release: 2016-05-16 17:46:58
Original
1463 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
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
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 }); }
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; }
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