HTML代码示例:输入内容调用接口并展示返回结果
输入内容
接口返回内容
<script>
function callAPI() {
var input = document.getElementById('input').value;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/api?input=' + input, true);
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
document.getElementById('output').innerHTML += '<p>' + this.responseText + '</p>';
}
}
xhr.send();
}
</script>
原文地址: https://www.cveoy.top/t/topic/lRmf 著作权归作者所有。请勿转载和采集!