没长正的技术专栏 勤动手、多思考

WEB 跨域

2015-01-07

阅读:

2020-09-11 11:28

本文主要给出跨域示例,方便用户本地模拟。建议将下面文件通过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>


Similar Posts

欢迎拍砖,多多交流,转载请注明出处:[没长正的技术专栏](http://blog.meizhangzheng.com) 如涉及侵权问题,请发送邮件到xsj34567@163.com,如情况属实本人将会尽快删除。


上一篇 WEB安全

下一篇 HTTPS证书

Comments