jqeuery $.ajax 与后台jsone交互

============================action后台,我这里是SpringMVC================================================
@Controller
@RequestMapping("pfun")
public class PubpowerfuncAction {
@Autowired
private PubpowerfuncServices pubpowerfuncServices;
 @RequestMapping("loadJb")
public String qryJbInfo(HttpServletRequest request,HttpServletResponse response) throws IOException {

List<Pubdll> list = pubpowerfuncServices.qrypubPowerfun();//查询数据
   //List转换成jsone类型

  Gson gson = new Gson();//需要导入 jar包我这里是gson-2.2.2.jar
  JsonReader reader = new JsonReader(new StringReader(list));
  String resultJson = gson.fromJson(reader, typeToken.getType());


response.getWriter().write(resultJson);
response.getWriter().close();
return null;
}
}

-======================================js===================
//用的是jquery Ajax
$.ajax({
type : 'post',
url : 'pfun/loadJb.hml?guid_dll='+ aguid,
success:function(data){
var dataObj=eval("("+data+")");
for(var i=0;i<dataObj.length;i++){

alert(dataObj[i].aguid);//获取后台的所有aguid

}
}
});

posted on 2013-09-03 12:53  qgc  阅读(256)  评论(0编辑  收藏  举报

导航