test.html 2.1 KB
Newer Older
B
improve  
binaryify 已提交
1 2
<!DOCTYPE html>
<html lang="en">
3 4 5 6 7 8
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>test</title>
    </head>
B
improve  
binaryify 已提交
9

10 11 12 13 14 15 16 17 18 19 20 21
    <body>
        <p>请在控制台看结果</p>
        <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
        <script>
            const phone = ''
            const password = ''
            const port = 3000
            if(!phone || !password){
              const msg = '请设置你的手机号码和密码'
              alert(msg)
              throw new Error(msg)
B
binaryify 已提交
22
            }
23 24
            $.ajax({
              url: `http://localhost:${port}/login/cellphone?phone=${phone}&password=${password}`,
B
binaryify 已提交
25 26 27
              xhrFields: {
                withCredentials: true //关键
              },
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
              success: function(data) {
                console.log(data)
                $.ajax({
                  url: `http://localhost:${port}/recommend/resource `,
                  xhrFields: {
                    withCredentials: true //关键
                  },
                  success: function(data) {
                    console.log(data)
                  },
                  error: function(err) {
                    console.log(err)
                  }
                })
              },
              error: function(err) {
                console.log(err)
              }
            })
B
improve  
binaryify 已提交
47

48
            axios({
B
binaryify 已提交
49 50
              url: `http://localhost:${port}/login/cellphone?phone=${phone}&password=${password}`,
              withCredentials: true //关键
51 52 53 54 55 56 57 58 59 60 61
            }).then(function(res) {
              console.log(res.data)
              axios({
                url: `http://localhost:${port}/recommend/resource`,
                withCredentials: true //关键
              }).then(function(res) {
                console.log(res.data)
              })
            })
        </script>
    </body>
B
binaryify 已提交
62
</html>