Javascript NodeJS,我可以在客户端的请求负载中看到数据,但在服务器端的请求对象中看不到数据

Javascript NodeJS,我可以在客户端的请求负载中看到数据,但在服务器端的请求对象中看不到数据,javascript,node.js,Javascript,Node.js,我正在尝试将数据从客户端发送到服务器节点。但在服务器上看不到数据。我错过了什么? index.html 如上述代码注释部分所述,request.data未定义。我尝试通过节点检查器可视化请求对象。但我没有看到通过客户端发送到服务器的数据。请评论我遗漏了什么。 提前感谢看起来像是重复的问题,请参考下面的答案 功能(请求、恢复){ 如果(请求方法=='POST'){ var jsonString=''; 请求开启(“数据”,功能(数据){ jsonString+=数据; }); 请求开启('end'

我正在尝试将数据从客户端发送到服务器节点。但在服务器上看不到数据。我错过了什么?
index.html

如上述代码注释部分所述,request.data未定义。我尝试通过节点检查器可视化请求对象。但我没有看到通过客户端发送到服务器的数据。请评论我遗漏了什么。

提前感谢

看起来像是重复的问题,请参考下面的答案

功能(请求、恢复){
如果(请求方法=='POST'){
var jsonString='';
请求开启(“数据”,功能(数据){
jsonString+=数据;
});
请求开启('end',函数(){
log(JSON.parse(jsonString));
});
}
}


stackoverflow.com/questions/4295782/如何提取节点js中的post数据

可能重复的post数据不起作用。我看不到数据进入服务器端。是因为我没有提交表格吗
如果我在上面的示例中提交表单,如何进行ajax调用?我非常确信数据不会从客户端传输到服务器。所以,delegate req.on('data')不起作用。我不是通过AJAX调用正确地提交了数据吗?
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
var testField = $('#testField').text();
$(document).ready(function() {
    $('#submit').on("click",function() {
        if ((!$('#testField').val())) {
            $('#error').text("Please enter Test");
        } else {
            $('#error').hide();
            console.log ("Ajax call");          
            console.log ("Inner Ajax call");
                $.ajax({
                    type: 'POST',
                    url: '/testUrl',
                    data: testField,
                    success: function(result) {
                        console.log ('Response Success:', result);
                    },
                    failure: function(result) {
                        console.log ('Response Failue:', result);
                    }
                });
        }
    });
});
</script>
</head>
<div id="testId">Test:<input type="text" name="testField" id="testField">     </div>
<div id="error"></div>
<div id="code"></div>
<div id="button"><input type="button" id="submit" value="Submit"></div>    
</html>
var http = require('http');
var fs = require('fs');
var qs = require('querystring');

function send404Response (response) {
    console.log ("send404Response");
    response.writeHead(404, {"Context-Type" : "text\plain"});
    response.write("Error 404: Page not found");
    response.end();
}

function onRequest(request, response) {
    console.log ("onRequest");
    if (request.method == 'GET' && request.url == '/') {
        console.log ("onRequest - GET - Home page");
        response.writeHead(200, {"Context-Type" : "text\plain"});
        fs.createReadStream ('./index.html').pipe(response);
    } else if ((request.type == 'POST' || request.method == 'POST') && (request.url == '/testUrl')) {
        console.log ("onRequest - POST - testUrl - " + request.data);   //request.data is undefined - how to receive data.
        response.end();
    } else {
        send404Response(response);
    }
}

http.createServer(onRequest).listen(8888);
console.log("Server is now running");