oauth2.0 判断接口是否允许跨域

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link type="test/css" href="css/style.css" rel="stylesheet">

<body>

	<input type="text" style="width:600px;height:30px;font-size:14px;" id="urlText" value="" />
	<br>
	<input type="button" style="margin: 10px";  id="cors" value="判断是否可访问"/>

<p>http://sz07.hrzhao.com/UEP/scenetest/GetSceneTestList.mt</p>
<p>10.209.158.160:8082/UEP/scenetest/GetSceneTestList.mt</p>
<p>10.209.158.160:9092/UEP/scenetest/GetSceneTestList.mt</p>
<script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>  
<script type="text/javascript">
    jQuery.support.cors = true
	$(function(){
	$("#cors").click(
		function(){
		//debugger
			var url2 = $("#urlText").val();
			//var requestData="grant_type=password&username=15528252046&password=abc1234";
			<!-- $.post({ -->
				<!-- contentType:'application/x-www-form-urlencoded;charset=UTF-8', -->
				<!-- url:url2, -->
				<!-- data: "/rAIeKeSBG1LV+XoIq82/O", -->
				<!-- success:function(data){ -->
                    <!-- debugger -->
					<!-- alert("success"); -->
				<!-- } -->
			<!-- }) -->
			
			$.ajax({
    url: url2,
    type: 'POST',
    beforeSend: function(xhr) {
        xhr.setRequestHeader("Authorization", "验证Token");
    },
	data: 'username=123123&password=34535&grant_type=password',
    dataType: 'json',
    crossDomain: true,
    //async: "false",
    headers: {
        'Content-Type': 'application/json;charset=utf8',
        'Authorization': '验证Token'
    },
    success: function(data) {
        console.log("sucess");
    },
    error: function(data) {
        console.log("error");
    }
});
		});
	});
</script>
</body>
</html>

  

posted @ 2020-12-02 18:53  摩诘  阅读(370)  评论(0编辑  收藏  举报