Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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请求_Javascript_Html_Http_Xmlhttprequest - Fatal编程技术网

Javascript 代码不发送HTTP请求

Javascript 代码不发送HTTP请求,javascript,html,http,xmlhttprequest,Javascript,Html,Http,Xmlhttprequest,我想在用户按下“发送JSON”按钮时从HTML页面发送HTTP请求。客户端实现如下所示: <html> <head> <title>Page</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head

我想在用户按下“发送JSON”按钮时从HTML页面发送HTTP请求。客户端实现如下所示:

<html>
    <head>
        <title>Page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>Page</div>            
        <p>Click the button below to send json</p>
        <button type="button" onclick="sendJson()">Send file</button>
        <p id="demo"></p>
        <script>            
            function sendJson()
            {
                var xmlhttp = new XMLHttpRequest();   
                xmlhttp.open("POST", "http://localhost:9000/test");
                xmlhttp.setRequestHeader("Content-Type", "application/json");
                var data = JSON.stringify({"email": "hey@mail.com", "password": "101010"});
                xmlhttp.send(data);
            }
        </script>
    </body> </html>

页
页
单击下面的按钮发送json

发送文件

函数sendJson() { var xmlhttp=new XMLHttpRequest(); open(“POST”http://localhost:9000/test"); setRequestHeader(“内容类型”、“应用程序/json”); var data=JSON.stringify({“email”:”hey@mail.com“,”密码“:“101010”}); 发送(数据); }
是服务器运行的URL


这段代码的问题是它不发送HTTP请求。这段代码有什么问题吗?

你能让js摆弄一下你的代码吗?它确实发送了请求。你在控制台中看到了什么?是的,我可以制作js提琴,js可以工作,但它不发送Http请求。你可以制作js提琴来处理你的代码吗?它会发送请求。您在控制台中看到了什么?是的,我可以制作js小提琴,js可以工作,但它不发送Http请求