注解跨域踩坑@CrossOrigin

原创
2019/12/19 17:57
阅读数 97

org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'keyword' is not present

花蛇添足了,

请求成功后台报错

后台报错

页面测试两者没啥区别就是Josn的区别都可

去掉后成功获取结果数据

不要放开注释掉的代码

否则就报下面的错误

最终拿到数据

附上html的测试代码。

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
  <script type="text/javascript" src="https://tugenhua0707.github.io/html5UploadImage/js/jquery.js"></script>
</head>
<body>
  <div id="app">
    <div class="btn"><button>发送post请求</button></div>
   
  </div>
 
 <a href="">tiaozhuan</a>
<p><span style="font-size 14.0pt;color: #ff9900;">&nbsp;</span></p> 

  <script>
    $('.btn').click(function() {
      $.ajax({
       // url: 'http://locahost:8080/sport/api/sportscmsnews/getnewinfo',
        //url: 'http://localhost:8080/sport/html/lottery/my-coin',
        //url: 'http://172.18.103.119:8080/franchisee/api/dimensional/code',
        url: 'http://localhost:8080/platform/api/dimensional/code',
        type: 'POST',
        //type: 'get',
        dataType: 'json',
        contentType: 'application/json',
        crossDomain:true,
        //xhrFields: {  withCredentials: true  },
        data: {keyword: "html",areaname:"html"},
        //data: JSON.stringify({keyword: "html",areaname:"html"}),
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.withCredentials = true;
           // XMLHttpRequest.setRequestHeader("access_token", "123");
           // XMLHttpRequest.setRequestHeader("timestamp", "123");
           // XMLHttpRequest.setRequestHeader("uid", "123");
        },
        success: function(d) {
          
        }
      })
    });
  </script>
</body>
</html>

头部信息放在了handlerInterceptor中了

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部