无法提取服务器端从客户端发送的数据

时间:2019-03-20 19:40:12

标签: javascript json ajax xmlhttprequest send

我有我的客户端,允许用户在输入框中输入文本。我希望将其从client.js中提取并将其发送到server.js,并将其存储在变量中。有人可以帮我吗?

var express = require('express');
var app = express();
var data = {
    user1: {name: "Brian", age: 33, alive: true},
    user2: {name: "Carol", age: 29, alive: true},
    user3: {name: "Sue", age: 103, alive: false}
};
app.get('/users/*', handleGetRequest);//Subfolders
app.get('/users', handleGetRequest);
app.use(express.static('public'));
app.listen(5000);
function handleGetRequest(request, response){
    var pathArray = request.url.split("/");
    var pathEnd = pathArray[pathArray.length - 1];
if(pathEnd === 'users'){
    response.send(JSON.stringify(data));
}
else if(pathEnd in data){
    var test = [request.data.name];
    console.log(test);
    response.send(JSON.stringify(data[pathEnd]));
}
else
    response.send("{error: 'Path not recognized'}");
}

Javascript for client side

0 个答案:

没有答案