本文主要给出跨域示例,方便用户本地模拟。建议将下面文件通过nginx容器中(配置nginx.conf)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<!-- cdn -->
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
console.log("start");
var param = {
"pageSize": null,
"pageNum": null,
"condition": [
{
"name": "id",
"value": 1
}
]
};
$(function(){
$("#cross").click(
function(){
$.ajax({
type: "post",
headers:{"Content-Type":"application/json;charset=UTF-8","Access-Control-Allow-Origin":"*","token":"XX"},
url:"http://127.0.0.1:9000/open/api/test",
data: JSON.stringify(param),
success:function(data){
console.log("start111")
console.log(data)
alert(data);
}
})
});
});
</script>
<body>
<input type="button" id="cross" value="跨域测试"
</body>
</html>