ajax处理用list<room>转换成的json对象总是执行error方法 10
js代码:$("#clickMe").click(function(){varurl="json/jsonTest.action";$.ajax({type:'get',...
js代码:
$("#clickMe").click(function(){
var url = "json/jsonTest.action";
$.ajax({
type:'get',
url:url,
dataType: 'json',
error : function(data) {
alert(data.toString()+"error");//总是执行这个方法,都不知错在哪
//弹出的是: [object,Object]error
},
success:function(data){
alert(data.toString())
$.each(data,function(i,list){
var _tr = $("<tr><td>"+list.name+"</td><td>"+
list.idCard+"</td><td>"+list.status+
"</td><td>"+list.message+"</td></tr>");
$("#showTable").append(_tr);
})
action处理代码:
public String execute(){
List<room> list =dao.getallroom();
JSONArray jsonArray = JSONArray.fromObject(list); //list转换成json 应该没错吧
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
response.setCharacterEncoding("UTF-8");
response.getWriter().print(jsonArray);
return null;
} 展开
$("#clickMe").click(function(){
var url = "json/jsonTest.action";
$.ajax({
type:'get',
url:url,
dataType: 'json',
error : function(data) {
alert(data.toString()+"error");//总是执行这个方法,都不知错在哪
//弹出的是: [object,Object]error
},
success:function(data){
alert(data.toString())
$.each(data,function(i,list){
var _tr = $("<tr><td>"+list.name+"</td><td>"+
list.idCard+"</td><td>"+list.status+
"</td><td>"+list.message+"</td></tr>");
$("#showTable").append(_tr);
})
action处理代码:
public String execute(){
List<room> list =dao.getallroom();
JSONArray jsonArray = JSONArray.fromObject(list); //list转换成json 应该没错吧
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
response.setCharacterEncoding("UTF-8");
response.getWriter().print(jsonArray);
return null;
} 展开
1个回答
展开全部
success:function(data){
alert(data.toString())//这里是不是少了个‘;’????
$.each(data,function(i,list){
var _tr = $("<tr><td>"+list.name+"</td><td>"+
list.idCard+"</td><td>"+list.status+
"</td><td>"+list.message+"</td></tr>");
$("#showTable").append(_tr);
})
alert(data.toString())//这里是不是少了个‘;’????
$.each(data,function(i,list){
var _tr = $("<tr><td>"+list.name+"</td><td>"+
list.idCard+"</td><td>"+list.status+
"</td><td>"+list.message+"</td></tr>");
$("#showTable").append(_tr);
})
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询