在ajaxSubmit提交表单的配置里面,增加一个参数,服务器端判断是否是ajaxSubmit提交过来的表单,是的话就返回“text/html”类型的内容,不是就可以返回“
application/json”的。
public void write(String msg,HttpServletResponse response) throws Exception { PrintWriter write = null; //response.setContentType("application/text;charset=UTF-8"); response.setContentType("text/html;charset=UTF-8"); response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires",0); try { write = response.getWriter(); write.write(msg); write.flush(); } catch (IOException e) { throw new Exception("ajax write error" + e.getMessage()); } finally { response = null; if (write != null) write.close(); write = null; } }
把文中注释的代码换成response.setContentType("text/html;charset=UTF-8")代码即可。
原文链接:https://www.f2er.com/ajax/165432.html