jquery ajax的success回调函数不执行

asn_yuan 2010-05-10 05:15:45
前台使用jquery的ajax查询数据
js代码:
$(function(){
$.ajax({
url:'findToAdmin.action',
type:'get',
data:{state:'admin'},
dataType:'json',
cache:false,
success:function(jsonData){
for(var i=0;i<jsonData.length;i++){
alert(jsonData[i].name);
}
},
error:function(){
}
});
});
java代码:
public String findToAdmin(){
String state=ServletActionContext.getRequest().getParameter("state");
Map<Object,Object> param=new HashMap<Object,Object>();
param.put("resType=?", state);

List<FunctionAuthority> authoritysList=functionAuthorityService.findToAdmin(param);

JSONArray jsonArray=new JSONArray();

for(int i=0;i<authoritysList.size();i++){

Map<Object,Object> map=new HashMap<Object,Object>();

map.put("id", authoritysList.get(i).getId());
map.put("name", authoritysList.get(i).getName());
map.put("parentId", authoritysList.get(i).getParentId());
map.put("resType", authoritysList.get(i).getResType());
map.put("descn", authoritysList.get(i).getDescn());

jsonArray.add(map);
}

String jsonStr=jsonArray.toString();
String jsonString="{jsonData:"+jsonStr+"}";
jsonUtils.outJson(jsonString);
return SUCCESS;
}
...全文
491 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
asn_yuan 2010-05-10
  • 打赏
  • 举报
回复
alert(XMLResponse.responseText)过了 直接就进了error 打出来的是后台传过来的json数据
牛叔 2010-05-10
  • 打赏
  • 举报
回复
看着头晕
调试一下
看请求有没有执行,有没有成功
小水晶 2010-05-10
  • 打赏
  • 举报
回复
在error里alert试试,没准是执行的流程错了,进error了
asn_yuan 2010-05-10
  • 打赏
  • 举报
回复
这是outJson方法:
public void outJson(String xmlStr) {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
try {
PrintWriter out = response.getWriter();
out.write(xmlStr);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧