jquery序列化form表单使用ajax提交后处理重返的json数据
发布时间:2023-10-20 15:38:44 所属栏目:教程 来源:
导读:返回json字符串:
代码如下:
/** 将一个字符串输出到浏览器 */
protected void writeJson(String json) {
PrintWriter pw = null;
try {
servletResponse.
代码如下:
/** 将一个字符串输出到浏览器 */
protected void writeJson(String json) {
PrintWriter pw = null;
try {
servletResponse.
返回json字符串: 代码如下: /** 将一个字符串输出到浏览器 */ protected void writeJson(String json) { PrintWriter pw = null; try { servletResponse.setContentType("text/plain;charset=UTF-8"); pw = servletResponse.getWriter(); pw.write(json); pw.flush(); pw.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (pw != null) { pw.close(); } } } 通过eval将返回的json字符串转换成json对象: 代码如下: $.ajax({ data:{ "shipmmsi":shipmmsi, "shipname":shipname }, url : "shipbk/findShipMMSIAndName.do", async : true, type : "POST", success : function(data) { var ships = eval('(' + data + ')'); $("#bindShipmmsiDiv table tbody").html(""); if(ships!=null){ if(ships.length){ $("#bindShipmmsiDiv").show(); var trs=""; for(var i=0;i<ships.length;i++){ trs+="<tr><td>"+ships[i].mmsi+"</td><td>"+ships[i].vesselName+"</td></tr>"; (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐