Files
2024-09-27 02:06:13 +08:00

108 lines
2.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ajax</title>
</head>
<body>
<div class="two"></div>
</body>
<script src="./js/config.js"></script>
<script src="./js/http.js"></script>
<script src="./js/server.js"></script>
<script>
// callback
// function ajax(option) {
// var xhr = new XMLHttpRequest();
// var GetParams = ""
// if (option.type == "GET") {
// for (const key in option.data) {
// GetParams += `&${key}=${option.data[key]}`
// }
// GetParams = GetParams.replace("&", "?")
// option.url += GetParams
// }
// xhr.open(option.type, option.url)
// xhr.setRequestHeader("Content-Type", "application/json; charset = UTF-8");
// xhr.send(option.type == "GET" ? null : JSON.stringify(option.data))
// xhr.onreadystatechange = function () {
// if (xhr.readyState == 4) {
// if (xhr.status == 200) {
// option.success(JSON.parse(xhr.responseText))
// } else {
// console.log("暂无数据");
// option.error(xhr)
// }
// }
// }
// }
// callback
// ajax({
// type: "POST",
// url: 'http://127.0.0.1/index.php',
// data: {
// id: 1,
// name: '张三'
// },
// success: function (res) {
// console.log("====== success: ", res);
// },
// error: function (err) {
// console.log("====== error: ", err);
// },
// })
// promise
// var http = new HTTP();
// http.get({
// url: 'http://127.0.0.1/index.php',
// data: {
// id: 1,
// name: '222'
// }
// })
// .then(function(res){
// console.log(res);
// })
// .catch(function(err){
// console.log(err);
// })
// console.log("=======");
var a = async () => {
let res = await server.index({ id: 1, name: '222' });
// var res = await http.get({
// url: 'http://127.0.0.1/index2.php',
// data: {
// id: 1,
// name: '222'
// }
// });
console.log("=== ",res);
}
a()
</script>
</html>