How to send data from client side to Node.js server using Ajax without page reloading ? Last Updated : 08 Jan, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we are learning about how can we send data to a node server using Ajax without reloading the page from the client-side.Approach: We are creating a button in HTML document on the client-side when the button is pressed a request is made on our node server and the object is received at our server without reloading the page. This can be done by Ajax request, we are sending data to our node server, and it also gives back data in response to our Ajax request. Step 1: Initialize the node modules and create the package.json file using the following command.npm initStep 2: Install express module locally into your system by using the following command.npm i express Step 3: Create script.js, index.html file in js folder as shown below.Project structure: It will look like the following. Step 4: Write down the following code in the given files. index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <style> .container { width: 500px; margin: auto; text-align: center; } </style> </head> <body> <div class="container"> <h1> Sending data to a node server using Ajax Request without Reloading Page </h1> <button id="submit">submit</button> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity= "sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"> </script> <script src="js/script.js"></script> </body> </html> script.js $(document).ready(function () { $("#submit").click(function () { $.post("/request", { name: "viSion", designation: "Professional gamer" }, function (data, status) { console.log(data); }); }); }); app.js const express = require("express") const path = require("path"); const app = express(); const port = process.env.PORT || 3000; // Setting path for public directory const static_path = path.join(__dirname, "public"); app.use(express.static(static_path)); app.use(express.urlencoded({ extended: true })); // Handling request app.post("/request", (req, res) => { res.json([{ name_recieved: req.body.name, designation_recieved: req.body.designation }]) }) // Server Setup app.listen(port, () => { console.log(`server is running at ${port}`); }); Step 5: Run the app.js file using the following command:node app.jsStarting node server Output: Comment More infoAdvertise with us Next Article How to send data from client side to Node.js server using Ajax without page reloading ? N namankumar2592 Follow Improve Article Tags : JavaScript Web Technologies Node.js Express.js Node.js-Methods NodeJS-Questions +2 More Similar Reads How to Send Response From Server to Client using Node.js and Express.js ? In web development, sending responses from the server to the client is a fundamental aspect of building interactive and dynamic applications. Express.js, a popular framework for Node.js, simplifies this process, making it easy to send various types of responses such as HTML, JSON, files, and more. T 4 min read How to Generate or Send JSON Data at the Server Side using Node.js ? In modern web development, JSON (JavaScript Object Notation) is the most commonly used format for data exchange between a server and a client. Node.js, with its powerful runtime and extensive ecosystem, provides robust tools for generating and sending JSON data on the server side. This guide will wa 3 min read How to submit a form or a part of a form without a page refresh using jQuery? How to prevent an HTML form to submit?When submitting a form, clicking the submit button usually navigates to a new route as specified in the form's action attribute. However, this can be done in the background using event.preventDefault(), which blocks the default event behavior. By attaching an on 2 min read How to get server response from an AJAX request using jQuery ? In this article, we will see how we can use jQuery to get the server response to an AJAX request. The jQuery ajax() method implements the basic Ajax functionality in jQuery. It communicates with the server via asynchronous HTTP requests. Syntax:$.ajax(url);$.ajax(url,[options]);Parameters:url: A URL 4 min read How to Generate/Send JSON Data at the Client Side ? Javascript Object Notation (JSON) is a widely used format for sending and receiving data to or from the server. In this article, we will use fetch API to send and receive data from the NodeJS server. Advantages of JSON: Because of its easy and small syntax, it executes the response in a faster way. 3 min read Like