**使用jsonp,即使设置ajax请求为POST,TM会将其转为GET请求. 这样web.xml设置的springmvc的CharacterEncodingFilter
不起作用.
执行request.setCharacterEncoding("utf-8")
对GET请求是无效的!**>(!错误!)
[更正]之所以会变成GET请求不是jsonp的过错,而是idea里面用浏览器打开html后,可以用http协议. 但是会将post换成get.
请看下面的请求头:
Request URL: http://localhost:8089/search.do?callback=jQuery11210772629357678043_1528177787309&searchType=%E5%A7%93%E5%90%8D&searchContent=%E6%9D%8E%E5%9B%9B&_=1528177787310
Request Method: GET
js
$.ajax({
type: 'POST',url: requestArguments.url,data: requestArguments.data,success: function (responseResult) {
}.bind(this),dataType: 'jsonp'</code></pre>
后台controller部分代码
头部:
@RequestMapping(value = {"/search"}) //http://localhost:8080/certno/110101195607302022.do
@ResponseBody
public MappingJacksonValue searchGraph(String searchType,String searchContent,@RequestParam(value = "callback",required = false) String callback,HttpServletResponse response) throws CustomException {
....
//构造MappingJacksonValue,SpringMVC配合jsonp<a href="/tag/jiejue/" target="_blank" class="keywords">解决</a>浏览器跨域访问问题
MappingJacksonValue mjv = new MappingJacksonValue(responseResult);
mjv.setJsonpFunction(callback);
return mjv;
**使用jsonp,TM会将其转为GET请求. 这样web.xml设置的springmvc的CharacterEncodingFilter
不起作用.
执行request.setCharacterEncoding("utf-8")
对get请求是无效的!**
所以,还是乖乖的将Tomcat的server.xml的配置改下吧.