客户端收到javascript的json对象 [英] Client receive json object to javascript
本文介绍了客户端收到javascript的json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望服务器将JSON对象发送到客户端的javascript.客户如何才能将对象放入其javascript中而不在屏幕上显示该对象?
I want my server to send a JSON object 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");
}
});
你明白我的意思吗?
这篇关于客户端收到javascript的json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文