使用jquery模拟请求,测试项目是否存在跨域限制

时间:2023-03-09 16:21:09
使用jquery模拟请求,测试项目是否存在跨域限制

1.Get 请求

<html>
<head><script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script></head>
<body>测试Get</body>
</html>
<script>
$(function(){
$.ajax({
type: "GET",
url: "http://192.168.9.14:8290/api/admin/user/getMenus",
success: function(msg){
alert( "Data: " + msg );
}
});
})
</script>

2.Post 请求

<html>
<head><script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script></head>
<body>测试post</body>
</html> <script>
$(function(){
$.ajax({
type: "POST",
url: "http://192.168.9.14:8290/api/admin/login",
data: ('{"username":"admin","password":"e10adc3949ba59abbe56e057f20f883e"}'),
contentType: "application/json",
dataType: "json",
success: function (msg) {
console.log(msg);
}
});
})
</script>