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

  • SEARCH
  • Home
  • 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 8959997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:34:25+00:00 2026-06-15T15:34:25+00:00

My ultimate goal is to send an arbitrary JSON to node.js when a button

  • 0

My ultimate goal is to send an arbitrary JSON to node.js when a button is clicked. I currently only know how to send input from a form. Here’s some code I put together to send form information:

function postForm() {
  $('form').submit(function(e) {
    e.preventDefault(); // no page reload
    $.post(
      $(this).attr('action'),
      $(this).serialize(),
      function(data) { console.log('Code for handling response here.') },
     'json'
    );
  });
}

Where the HTML looks like:

<form action='/send' method='post'>
  <input name= "foo" type="radio" value=1>
  <input type="submit" value="Submit">
</form>

And the relevant express/node.js code looks like:

app.post('/send', function(request, response) {
  fs.appendFile('test.txt', JSON.stringify(request.body) + '\n', function(e) {
    if(e) throw e;
    console.log(request.body);
  });
});

However, I don’t know how to adapt this example to use data that is not from form input. To give context, I’m building a web-based user study, and I want to send various information collected about the user to node.js. I’ve tried variants of what was working for the form submission, but none of my attempts have been successful. My impression was that I could just swap out $(this).serialize() to any other data that the client can access, but I couldn’t get this line of thought to work. I also tried altering some of the many .ajax() examples, but those always redirected the page which is undesirable, since my study will lose user-state information if the page refreshes.

I’ve done decent amount of client and server side programming, but I have next to no knowledge about how ajax works, which is proving rather problematic for solving this! And also rather silly since, often times, that’s what glues the two together 🙂

  • 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-06-15T15:34:26+00:00Added an answer on June 15, 2026 at 3:34 pm

    Since you’re using jQuery, sending data is simple – call $.post(url, data) from the button’s click handler:

    $('#somebutton').click(function() {
        var data = { key: 'value', ... };
        $.post('/send', data, function(res) {
            // success callback
        });
    });
    

    The browser will POST to url with a URL-encoded serialization of the data argument.

    POST /send HTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    ...
    
    key=value&...
    

    Which Express’ bodyParser will have no trouble with. Alternatively, you can tell jQuery to send a JSON serialization of data:

    $.post('/send', data, function(res) {}, 'json');
    

    In your case, it really doesn’t matter how jQuery transmits the data (URL encoded or JSON), since bodyParser automatically deserializes both formats.

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

Sidebar

Related Questions

The ultimate goal of this project is to send low level input (so that
My ultimate goal is to allow users to select a file from a dialog
Here is my ultimate goal... to take this xml file.. <?xml version=1.0?> <Songs> <Song>
Here's my ultimate goal in all of this. I have a viewcontroller with a
My ultimate goal is to append the JSON data to ul#tweets , each as
The ultimate goal is to use JSFL to export a 2D skeleton from Flash.
My ultimate goal is to write a sql script that selects data from a
The ultimate goal is to have a div animate down when the button is
My ultimate goal is to have a menu that adds a class to the
My ultimate goal is to load controls as plugins, for use as DocumentContent in

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.