---------------------------------------------前台:
$(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' 就是objectvar jsonData=eval("("+data+")"); for(var i=0;i
}
--------------------------------定义为dataType : 'text'