ajax后臺處理返回json值示例代碼
更新時(shí)間:2013年09月05日 17:38:28 作者:
很多的新手朋友們不知道ajax如何處理返回json值,在本文將為大家詳細(xì)介紹下
復(fù)制代碼 代碼如下:
public ActionForward xsearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String parentId = request.getParameter("parentId");
String supplier = request.getParameter("supplier");
List itemList = new ArrayList();
if(parentId.equals("")){
parentId="0";
}
Map map=new TawApTreeServlet().getTypeList(parentId, supplier);
for (Iterator rowIt = map.keySet().iterator(); rowIt.hasNext();) {
String id = (String) rowIt.next();
TawCommonsUIListItem uiitem = new TawCommonsUIListItem();
uiitem.setItemId(id);
uiitem.setText((String)map.get(id));
uiitem.setValue(id);
itemList.add(uiitem);
}
response.setContentType("text/xml;charset=UTF-8");
// 返回JSON對象
response.getWriter().print(JSONUtil.list2JSON(itemList));
return null;
}
您可能感興趣的文章:
- html+js+php一次原始的Ajax請求示例
- jquery教程ajax請求json數(shù)據(jù)示例
- 使用$.getJSON實(shí)現(xiàn)跨域ajax請求示例代碼
- jQuery中使用Ajax獲取JSON格式數(shù)據(jù)示例代碼
- jquery ajax對特殊字符進(jìn)行轉(zhuǎn)義防止js注入使用示例
- 通過AJAX的JS、JQuery兩種方式解析XML示例介紹
- AJAX如何接收J(rèn)SON數(shù)據(jù)示例介紹
- jQuery的ajax傳參巧用JSON使用示例(附Json插件)
- 淺析ajax請求json數(shù)據(jù)并用js解析(示例分析)
- JavaScript中的ajax功能的概念和示例詳解
相關(guān)文章
如何創(chuàng)建ajax對象并兼容多個(gè)瀏覽器
這篇文章主要介紹了創(chuàng)建ajax對象并兼容多個(gè)瀏覽器方法簡單記錄,在某些情況下還是比較實(shí)用的,需要的朋友可以參考下2014-08-08
Ajax獲取到數(shù)據(jù)放入echarts里不顯示的原因分析及解決辦法
在做一個(gè)需要用到echarts地圖的項(xiàng)目的時(shí)候,成功通過ajax獲取到了后臺提供的數(shù)據(jù),并生成了想要的JSON串。但是,放到echarts option.series[0].data里,獲取不到數(shù)據(jù)。在生成的地圖上無法看到你從后臺獲取到的值,下面小編給大家分享我的解決辦法,需要的朋友參考下2016-01-01
解決spring mvc 返回json數(shù)據(jù)到ajax報(bào)錯(cuò)parseerror問題
最近使用ajax接收spring mvc傳過來的json數(shù)據(jù)時(shí)總是出現(xiàn)parseerror的錯(cuò)誤,下面通過本文給大家分享spring mvc 返回json數(shù)據(jù)到ajax報(bào)錯(cuò)parseerror問題的解決方法,需要的朋友參考下吧2017-05-05
Ajax Session失效跳轉(zhuǎn)登錄頁面的方法
這篇文章主要介紹了Ajax Session失效跳轉(zhuǎn)登錄頁面的方法,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-06-06

