前端之家收集整理的这篇文章主要介绍了
Ajax(JavaScript),
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
function success(text) {
var textarea = document.getElementById('test-response-text');
textarea.value = text;
}
function fail(code) {
var textarea = document.getElementById('test-response-text');
textarea.value = 'Error code: ' + code;
}
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
return success(request.responseText);
} else {
return fail(request.status);
}
} else {
}
}
request.open('GET','/api/categories');
request.send();
alert('请求已发送,请等待响应...');
原文链接:https://www.f2er.com/ajax/160774.html