手动实现传统的ajax
<script>
function request(method, url, data, success) {
var ajax = new XMLHttpRequest();
if (method.toLowerCase() == 'get') {
if (data) {
url = `${url + '?'}${data}`;
} else {
}
ajax.open(method, url);
ajax.send();
} else {
}
ajax.onreadystatechange = function () {
if (ajax.readyState === 4 && ajax.status === 200) {
success(JSON.parse(ajax.responseText));
}
}
}
<!-- 调用自己定义的函数 -->
request('get', 'https://autumnfish.cn/search', 'keywords="Stay"', success);
function success(res) {
console.log(res);
}
</script>