在 php 中有很多方法可以做到这一点,但我不是服务器端,那么有没有办法在纯 JS 中做到这一点?
Pure JS? Yes, but only on the server (the specifics would depend on which SSJS implementation you use, Express + NodeJS is popular at present).
You can't receive a POST request on the client. The client makes the request. The server makes the response. That is how HTTP works.
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();
}
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.