Skip to content Skip to sidebar Skip to footer

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 :

Solution 1:

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 respondsconsole.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?

Solution 2:

Try to use res.json() method

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

Post a Comment for "Client Receive Json Object To Javascript"