天天看點

模拟跨域請求前台頁面代碼模拟跨域請求前台頁面代碼

模拟跨域請求前台頁面代碼

被調用方背景代碼編寫

調用方前台代碼編寫

引入前台Jasmine測試架構

1、建立Spring Boot工程

模拟跨域請求前台頁面代碼模拟跨域請求前台頁面代碼

建立Spring Boot工程

模拟跨域請求前台頁面代碼模拟跨域請求前台頁面代碼

建立Spring Boot工程

模拟跨域請求前台頁面代碼模拟跨域請求前台頁面代碼

Web-Web提供Web服務

2、建立HTML頁面

模拟跨域請求前台頁面代碼模拟跨域請求前台頁面代碼

index.html代碼

<!DOCTYPE html>

<html >

<head>

    <meta charset="UTF-8">

    <title>ajax-cross-doman</title>

    <!-- minified -->

    <script src="jquery-1.11.3.min.js"></script>

</head>

<body>

    <a href="#" target="_blank" rel="external nofollow" οnclick="get1()">發生get請求</a>

    <script type="text/javascript">

        function get1(){

            $.getJSON("http://localhost:8081/test/get1").then(

                function(result){

                    console.log(result)

                }

            )

        }

    </script>

</body>

</html>

3、下載下傳jQuery庫

模拟跨域請求前台頁面代碼模拟跨域請求前台頁面代碼

繼續閱讀