spring mvc 避免IE执行AJAX时,返回JSON出现下载文件
controller
@RequestMapping(value = "/com/testjson", produces = { "text/plain;charset=UTF-8" }) public @ResponseBody String testjson(HttpServletRequest request){ Map<String,Object> m = new HashMap<String,Object>(); ...... return new JSONObject(m).toString(); }
页面
$(‘#testFm‘).form(‘submit‘, { url : ‘com/testjson‘, type : "POST", onSubmit : function() { ...... return validate; }, success : function(data) { data = $.parseJSON(data); ...... } });
web.xml 设置编码
<filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
spring mvc 避免IE执行AJAX时,返回JSON出现下载文件
原文地址:http://davidsolomon.blog.51cto.com/3295360/1611534