ajax获取的全部是object,我要获取的是json
---------------------------------------------前台:$(document).ready(function(){vardata=...
---------------------------------------------前台:
$(document).ready(function() { var data= []; $.ajax({ type : 'post', url : 'orginfo.do?action=getName', cache : false, processData : true, dataType : 'json', success : function(data) { alert(data); }, async: false });
});
---------------------------------------------后台:
else if ("getName".equals(action)) { List<?> TableList=orgTableDAO.getName(); List<CheckBoxTree> treeList = getNameList(TableList); String aa=null; StringBuffer sb = new StringBuffer(); sb.append("["); for (int i = 0; i < TableList.size(); i++) { if (i != 0) { sb.append(","); } aa=treeList.get(i).toJSONStringName(); aa=aa.replace("'", "\""); sb.append(aa); } sb.append("]"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0L); response.setContentType("text/html; charset=GBK"); response.getWriter().write(sb.toString()); response.getWriter().close();-------------------定义为-- dataType : 'json' 就是object
}
--------------------------------定义为dataType : 'text'
嗯,我弄错了,不需要取键,只需要取值 展开
$(document).ready(function() { var data= []; $.ajax({ type : 'post', url : 'orginfo.do?action=getName', cache : false, processData : true, dataType : 'json', success : function(data) { alert(data); }, async: false });
});
---------------------------------------------后台:
else if ("getName".equals(action)) { List<?> TableList=orgTableDAO.getName(); List<CheckBoxTree> treeList = getNameList(TableList); String aa=null; StringBuffer sb = new StringBuffer(); sb.append("["); for (int i = 0; i < TableList.size(); i++) { if (i != 0) { sb.append(","); } aa=treeList.get(i).toJSONStringName(); aa=aa.replace("'", "\""); sb.append(aa); } sb.append("]"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0L); response.setContentType("text/html; charset=GBK"); response.getWriter().write(sb.toString()); response.getWriter().close();-------------------定义为-- dataType : 'json' 就是object
}
--------------------------------定义为dataType : 'text'
嗯,我弄错了,不需要取键,只需要取值 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询