客户免费获赠JSON对象的JavaScript [英] Client recieve json object to javascript

查看:179
本文介绍了客户免费获赠JSON对象的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的服务器发送一个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?

这篇关于客户免费获赠JSON对象的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆