$.ajax({
"type": "GET",
"url": "/itemsqry.action",
"data": {"report_no":$("#huoquselcet").val()},
"dataType": "json",
"success": function(data){
$('#itemcellselect').empty(); //清空resText里面的所有内容
var html = "";
$.each(data, function(index, value){
html = "" + value.item_name +"";
$('#itemcellselect').append(html);
});
},
"error":function(){
alert("网络错误!");
}
});
entities
#
这是struts的action:
public String itemsqry(String report_no){
System.out.println(report_no);
items.setReport_no(report_no);
this.itemsList = reportBiz.getItems(items);
if (itemsList == null) {
return null;
}
JSONArray array = new JSONArray(); //数组
JSONObject jsOb = new JSONObject();; //json对象
JSONObject jsonObject = null; //json对象
Items info = null;
for (int i = 0; i < itemsList.size(); i++) {
info = itemsList.get(i);
jsonObject = new JSONObject();
jsonObject.put("report_no", info.getReport_no());
jsonObject.put("item_cell", info.getItem_cell());
jsonObject.put("item_name", info.getItem_name());
jsonObject.put("item_type", info.getItem_type());
array.add(jsonObject);
}
jsOb.put("data", array);
return jsOb.toString();
}
return String 是你struts要返回页面,
你这应该方法为VOID 用 PrintWriter 输出
HttpServletResponse resp = ServletActionContext.getResponse();
resp.setContentType("text/html; charset=UTF-8");
PrintWriter out = resp.getWriter();
out.write(str);
你debug一下,到后台方法了吗
前台请求的数据类型dataType: json,后台返回的是string,数据类型不一样,前端的ajax请求就失败了
你的action少了一个传数据到前台的action
你先看是不是到后台方法了,到了的话再看是不是传数据回来了