asdsd asdsd - 3 months ago 12
Ajax Question

Client receive json object to 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?

In my server :

app.get('/', function (req, res) {
res.send(jsonObj);
});


Thank you!

Answer

Using jquery i will show you a quick example of how things work:

Client

$.get('youserver.com/', {mydata: 'content'}, function(response){
   //callback triggered when server responds
   console.log(JSON.stringify(response));
});

Server

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?

Comments