下面的代码使用 AJAX 请求通过我的 Express 服务器发送数据。我需要在发送后在我的 express 服务器上访问该数据以进行一些操作。我该怎么做呢?
Express 服务器片段:
app.get("/time",function(req,res){
client.messages.create({
to: "+1" + req.data.number,
from: '+166**',
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
mediaUrl: "https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg",
});
});
Ajax 请求:
$.ajax({url: "/time",
data : { name : 'Justin', number : '662***' }
});
最佳答案
如果您正在谈论服务器中的 GET 变量:
app.get("/time",function(req,res){
client.messages.create({
to: "+1" + req.params.number, // should be `req.params` instead
from: '+166**',
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
mediaUrl: "https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg",
});
console.log(req.params.name)
console.log(req.params.number)
});
如果你说的是服务器的响应,那么:
$.ajax({
url: "/time",
data : { name : 'Justin', number : '662***' }
}).done(function (response) {
console.log(response)
});
这个问题我看了三遍,还是没明白问什么,抱歉。
关于javascript - 在 Express 服务器上获取从 AJAX 发送的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41047771/