Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:58:18+00:00 2026-05-27T15:58:18+00:00

I use node.js and express. When I press the button (btnSend), I want to

  • 0

I use node.js and express. When I press the button (btnSend), I want to send data to node.js by express (without refresh the page). How do I send data using jQuery?

<form action="/Send" method="post">
Username: 
<input type="text" name="user" id="txtUser" />
<input type="submit" value="Submit" id="btnSend" />
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:58:18+00:00Added an answer on May 27, 2026 at 3:58 pm

    Here’s a rough outline of what your jQuery should look like:

    $("form").submit(function(e) {
        e.preventDefault(); // Prevents the page from refreshing
        var $this = $(this); // `this` refers to the current form element
        $.post(
            $this.attr("action"), // Gets the URL to sent the post to
            $this.serialize(), // Serializes form data in standard format
            function(data) { /** code to handle response **/ },
            "json" // The format the response should be in
        );
    });
    

    This code snippet finds all form elements on the page and listens for a submit event from them. A form can be submit in a number ways (e.x. clicking a submit button, hitting enter, etc…), so for the sake of usability, it’s best to listen for submit events directly opposed to listening for click events key on submit buttons.

    When a submit event does occurs, the code above first prevents the default browser actions (which among other things refreshes the page) by calling e.preventDefault. It then uses $.post to send the form data to the url specified in the action attribute. Note that $.fn.serialize is used to serialize the form data in a standard format.

    Your express code should look something like this:

    var express = require('express')
      , app = express.createServer();
    
    app.use(express.bodyParser()); // Automatically parses form data
    
    app.post('/Send', function(req, res){ // Specifies which URL to listen for
      // req.body -- contains form data
    });
    
    app.listen(3000);
    

    The documentation on express.bodyParser is a bit sparse, but after a bit of code spelunking it looks like it uses node-querystring underneath the covers.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Node.js together with Express framework and i18n module . So I use
I'm trying to send the node instance JSON data using an ajax get request
I use node.js - Express. I have a page (index.html) and html div (id
Can anyone use node.js (express.js or whatever) for a data-driven website like e-commerce?
I'm using node.js and the less compiler middleware: app.configure(function() { // ... app.use(express.compiler({ src:
I want to use LabVIEW's Call Library Function Node to access a DLL function,
I need to insert the comment form directly to the node template (I use
Is it safe to do something like this in Node.js/Express.js? // use Object.create(null) so
I'm trying to set up a simple project using Node.js and Express with Expresso
I'm writing a login for a website in node.js using the express framework. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.