1. 程式人生 > 其它 >01-springboot新建專案\配置檔案\配置檔案優先順序

01-springboot新建專案\配置檔案\配置檔案優先順序

//jQuery
        $(function () {
            $("button").click(function () {
                //   console.log(1);
                $.ajax({
                    url: "http://127.0.0.1:3000/",
                    method: "GET",
                    success(data) {
                        console.log(data);
                    },
                    error(e) {
                        console.log(e.statusText);
                    }
                })
            })
        })
//JavaScript
        let btn = document.querySelector("button");
        btn.onclick = function () {
            //1.建立一個非同步物件
            var xmlhttp = new XMLHttpRequest();
            //2.設定請求方式和請求地址
            /*
            2.1.method:請求型別:get或post
            2.2.URL:檔案在伺服器的地址
            2.3.async:true(非同步)或false(同步)
            */
            xmlhttp.open("GET", "http://127.0.0.1:3000/", true);
            //3.傳送請求
            xmlhttp.send();
            //4.監聽狀態變化
            xmlhttp.onreadystatechange = function () {
                // 0: 請求未初始化
                // 1: 伺服器連線已建立
                // 2: 請求已接收
                // 3: 請求處理中
                // 4: 請求已完成,且響應已就緒
                console.log(xmlhttp.readyState);
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status >= 200 && xmlhttp.status < 300 || xmlhttp.status === 304) {
                        //5.返回處理結果
                        //  console.log("succes");   
                        //獲取ajax返回的值  responeseText
                        console.log("success");
                        console.log(xmlhttp.responseText);
                    }
                    else {
                        console.log("error");
                    }
                }

            }

        }

node.js

//1.載入http核心模組
var http = require('http');

//2.使用http.creatServer()方法建立一個web伺服器
//返回一個Server例項
var server = http.createServer();

//3.註冊request請求事件
//當客戶端請求過來,就會自動觸發伺服器的request請求事件,然後執行
server.on('request', function (rquest, response) {
    // 解決跨域問題
    response.setHeader("Access-Control-Allow-Origin", "*");
    
    console.log("收到客戶端請求");

    response.end("data");
})

//4.繫結埠號,啟動伺服器
server.listen(3000, function () {
    console.log("伺服器啟動成功,可以通過http://127.0.0.1:3000/進行訪問");
})