In this tutorial I will show how to make a easier Ajax request using Node.js with the module Express.
The page shows how to summ 2 numbers, take the result throgh jQuery and show an alert box on your browser.
The web server works on the port 3000. Also you can see how load static page into your Node.js project. THe directory HTML contains the pure HTML static pages and in the directory JS the jQuery library.
Default homepage
var options = {
index: "index.html"
};
Change the index var with your static homepage file.
var options = {
index: "index.html"
};
In the sum.html we set our 2 data to sum up then we make an async Ajax request toward your Nodejs server to the URL /sum. This path in the webserver gets the 2 incoming parameters, sum them up and give back the value. On our web page we can see the sum shown as an alert to the user.