做简单POST的问题

时间:2015-10-14 18:42:56

标签: javascript http post

我试图从Javascript做一个简单的HTTP帖子。在下面的代码中,第24行的断点命中,但25上的断点没有。第26行也没有被处理(我添加它只是为了尝试别的东西)。虽然我可以在浏览器中手动输入该URL并查看连接,但服务器也没有获得连接。我也看到第22行的控制台输出,所以我知道该功能正在触发。

enter image description here

subscription.then(function() {
    console.log("connected to server");
    //request back load of data
    xhttp.open("POST", "http://localhost:8000/getData", true);
    xhttp.send();
    $.post("http://localhost:8000/getData")
});

我错过了什么?

1 个答案:

答案 0 :(得分:2)

也许您忘记创建XMLHttpRequest对象了?

subscription.then(function() {
    console.log("connected to server");
    //request back load of data
    var request = new XMLHttpRequest(); // creating request object
    request.open("POST", "http://localhost:8000/getData", true);
    request.send();
});