ajax 遍历list
//遍历方法一
var obj = eval("("+msg+")");
for(var i=0;i<obj.length;i++){ alert(obj[i]) }//遍历方法二
var jsonObj=eval("("+msg+")"); $.each(jsonObj, function (i, item) { alert(item); }); //遍历方法三 var jsonObj=eval("("+msg+")"); $(jsonObj).each(function(index){//注意function写法不一样 alert(jsonObj[index]); });
struct2
js
function testAjax(){
$.ajax({ type: "POST", url: "<%=path + "/queryHistoryDiff/queryHistoryDiffAction!test.action"%>", data: {hh : 'hh',pp : 'pp'}, success: function(msg){ alert(msg); } }); }
action
public String test() throws IOException {
String hh = this.getP("hh"); System.out.println(hh); PrintWriter out = getResponse().getWriter(); out.write("test"); return null; }-----------------------------------------------------------------------------------------
springMVC
js
function ajaxWarningInfo(n){
$('#pageNo').val(n); $.ajax({ type: "POST", url: "/warningMsg/list.htm", data: $('#searchWarningMsg').serialize(), dataType: "html", beforeSend: function (){ $('#listWarningMsg').html("<div style='text-align: center;'>" + "<img src='/img/loading.gif' style='margin: 30px auto 0px auto;' />" + "<br /><br />正在玩命加载中..请稍等<br /><br /><br />" + "</div>"); }, success: function (msg) { $('#listWarningMsg').html(msg); pageOrder(); } });}
controller
@RequestMapping("/list")
public ModelAndView searchOrderInfo(FormWarningMsg warningMsgForm) throws Exception {
// 将查询条件放入session(query.jsp)
setSessionAttr("fo", warningMsgForm);ModelAndView mv = new ModelAndView("/monitoringSku/warningMsgList");
// 分页查询订单信息
Page<EntityWarningMsg> page = warningMsgService.searchWarningMsgByPage(warningMsgForm); // 将map结果集转为list集合 page.resultList = ObjectUtil.batchMapToClass(EntityWarningMsg.class, page.resultMap); // 添加根据id查询到的提醒人名字 warningMsgService.getEmployeeByEmpSQ(page.resultList); // 将分页结果放入list.jsp页面 mv.addObject("page", page); return mv; }