I have already get a serier of json data from facebook using node js express. Now I want to send the data to a html page. But I have no idea how to send the data and encode the data in html.
The jQuery code uses getJSON() method to fetch the data from the file's location using an AJAX HTTP GET request. It takes two arguments. One is the location of the JSON file and the other is the function containing the JSON data. The each() function is used to iterate through all the objects in the array.
send() as well, as far as I am concern, latest express will add application/json Content-Type if you try to send object. It is up to jQuery to parse it properly. Although if Content-Type is not json but you still sure it will be always json, then you can force it in jQuery by adding dataType: 'json' in parameters in $.
If you use Express in node.js, here is the way to send json object as response:
app.get('/test', function(req, res, next) {
res.json({ message: 'Hello World' });
});
Then in JS on your html page html, if you use jQuery:
$.ajax({
url: '/test',
complete: function(data) {
console.log(data);
}
});
Feel free to experiment with stuff, as well use Dev Tools in Chrome, experimentation - helps a lot to understand what and how it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With