写一个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/CC0 著作权归作者所有。请勿转载和采集!