由网友(学长、你好衰)分享简介:我希望我的服务器发送一个JSON oject到客户的身边一个JavaScript。如何在客户端获取对象进入他的JavaScript,而不是显示对象在屏幕上?I want my server to send a json oject to a javascript on the client's side. How c...
我希望我的服务器发送一个JSON oject到客户的身边一个JavaScript。如何在客户端获取对象进入他的JavaScript,而不是显示对象在屏幕上?
I want my server to send a json oject to a javascript on the client's side. How can the client get the object into his javascript and not show the object on screen?
在我的服务器:
app.get('/', function (req, res) {
res.send(jsonObj);
});
感谢您!
推荐答案
使用jQuery我会告诉你的东西是如何工作的一个简单的例子:
Using jquery i will show you a quick example of how things work:
客户端
$.get('youserver.com/', {mydata: 'content'}, function(response){
//callback triggered when server responds
console.log(JSON.stringify(response));
});
服务器
app.get('/', function (req, res) {
if(req.params.mydata === 'content'){
res.end("you sent content");
} else {
res.end("you sent something else");
}
});
你明白我的意思吗?
Do you understand what i mean?
相关推荐
最新文章