You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CORS跨域 客户端</title>
<script type="text/javascript" src="Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript" src="Scripts/jquery.cookie.js"></script>
<script>
$(function () {
$("#MenuLinks li").click(function () {
var ajaxUrl = $(this).attr("url");
var ajaxMethod = $(this).attr("method");
var ajaxContentType = $(this).attr("contentType");
$.ajax({
//请求方法
type: ajaxMethod,
//请求地址
url: ajaxUrl,
//服务器返回类型
dataType: "html",
//发送类型
contentType: ajaxContentType,
//data: JSON.stringify({ "userName": "wanggaofeng", "userPassword": "213464" }),
beforeSend: function (xhr) {
$("#ContentBox").html("请求中...");
},
success: function (jsonData) {
$("#ContentBox").html(jsonData);
},
error: function (xhr,status,error) {
$("#ContentBox").html("请求错误" + error);
},
complete: function (xhr,status) {
}
});
});
$("#MenuLinks li:first").click();
});
</script>
</head>
<body>
<div id="MenuLinks">
<ul>
<li method="GET" dataType="json" contentType="application/x-www-form-urlencoded" url="http://localhost:5000/api/Test/Ping">简单API</li>
<li method="GET" dataType="json" contentType="application/x-www-form-urlencoded" url="http://localhost:5000/api/Cors/Ping">全局跨域策略</li>
<li method="GET" dataType="json" contentType="application/x-www-form-urlencoded" url="http://localhost:5000/api/Cors/NoCors">不允许跨域</li>
<li method="GET" dataType="json" contentType="application/x-www-form-urlencoded" url="http://localhost:5000/api/Cors/HasCors">单独明确可以跨域</li>
</ul>
</div>
<pre id="ContentBox">
默认内容
</pre>
</body>
</html>