JSONP
前端
<html>
<head>
<meta charset="uft-8">
</head>
<body>
<p>cors跨域设置。</p>
<button id="buttonId" >点击哈哈哈</button>
<input type="text" id="a"></input>
<input type="text" id="b"></input>
<input type="text" id="c"></input>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
$("#buttonId").click(function(){
$.ajax({
url:'http://localhost:8080/api/ceshi/c',
dataType:'jsonp',
type:'GET',
jsonp: 'callback',
jsonpCallback: 'jsonpCallback',
success:function(data) {
console.info("==="+data);
$("#b").val(data);
}
});
});
</script>
</body>
</html>
后端 (springboot框架)