Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中获取http.post,然后发送响应_Javascript_Http_Response - Fatal编程技术网

在javascript中获取http.post,然后发送响应

在javascript中获取http.post,然后发送响应,javascript,http,response,Javascript,Http,Response,在php中有很多方法可以做到这一点,但我不是服务器端,那么在纯JS中有什么方法可以做到这一点吗?纯JS?是的,但只在服务器上(具体取决于您使用的SSJS实现,Express+NodeJS目前很流行) 您无法在客户端上接收POST请求。客户机发出请求。服务器做出响应。这就是HTTP的工作原理。 <script> function showHint(str) { if (str.length == 0) { document.getElementById("tx

在php中有很多方法可以做到这一点,但我不是服务器端,那么在纯JS中有什么方法可以做到这一点吗?

纯JS?是的,但只在服务器上(具体取决于您使用的SSJS实现,Express+NodeJS目前很流行)

您无法在客户端上接收POST请求。客户机发出请求。服务器做出响应。这就是HTTP的工作原理。


<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>
函数showHint(str){ 如果(str.length==0){ document.getElementById(“txtHint”).innerHTML=“”; 返回; }否则{ var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=函数(){ if(xmlhttp.readyState==4&&xmlhttp.status==200){ document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText; } }; open(“GET”、“gethint.php?q=“+str,true”); xmlhttp.send(); } }