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 7761041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:02:59+00:00 2026-06-01T14:02:59+00:00

Edit Make sure you don’t juxtapose the request and response objects. things will be

  • 0

Edit

Make sure you don’t juxtapose the request and response objects. things will be easier if you dont.

I am trying to POST data from a form with two inputs to a specific url node responds to.
Originally I was using the javascript xmlHTTPrequest object to send it. The data was received but node could never read the object I tried sending which was JSON format. Here is what it looked like when I converted it to a string:

{ output: [], 
  outputEncodings: [],
  writable: true,
  _last: false,
  chunkedEncoding: false,
  shouldKeepAlive: true,
  useChunkedEncodingByDefault: true,
  _hasBody: true,
  _trailer: '',
  finished: false,
  socket: 
   { _handle: 
      { writeQueueSize: 0,
        socket: [Circular],
        onread: [Function: onread] },
     _pendingWriteReqs: 0,
     _flags: 0,
     _connectQueueSize: 0,
     destroyed: false,
     errorEmitted: false,
     bytesRead: 8442,
     bytesWritten: 1669569,
     allowHalfOpen: true,
     writable: true,
     readable: true,

This was not the full string. I switched over to use an ajax post request instead because I thought serializearray() might create a different format that node could read but it was the same. My server side code is essentially just:

function email(request, response)
  form = '';
  request.setEncoding("utf8");
  request.on('data', function(chunk) {
    console.log('data received');
    form += chunk.toString();
  });

  request.on('end', function() {
    console.log('done receiving post data');
  });

My form looks like this

  <form name="email" action="javascript:true;">
    <input type="text" name="address" value="Enter your email address" onFocus="this.value=''">
    <input class="special" type="text" name="honeypot">
    <input type="submit" value="submit">
  </form>

If I try parsing with JSON.parse, there is an error caused by unexpected o
If I try parsing with querystring, it returns an empty object
If I try something like console.log(form.address) the output is undefined but should be one of the values i submitted in the form.

my http server would route to /email and this is the function that responds to /email.

I checked and I know the on ‘data’ event has not expired because my code is set up to notify me of a ‘data’event and I can see the event happening. Locally, this code works fine and I can read the data submitted but on the development server it just doesn’t work.

I know people will say I should be using connect or express but let’s just suppose that was not an option, how could I get node to correctly process this data? The jquery that submits the form is more or less standard. Many thanks!

EDIT:

Sorry, I thought the problem would be fixed as I noticed immediately the posted string was not JSON. Here is the code I am using to send the post.

$(document).ready(function() {
  $("#email").submit(function(event) {
  event.preventDefault();
  var data = $(this).serializeArray();
  $.ajax({
    type: 'POST',
    dataType: 'json',
    url: '/email',
    data: JSON.stringify(data),
    success: function(msg) {
    $("#aviso").html(msg);
    }
    });
  });
}); 

Here is the string the data variable holds:

[
  {
    "name": "address",
    "value": "foo@bar.com"
  },
  {
    "name": "honeypot",
    "value": "irobot"
  }
]

This is valid JSON as per jsonlint. But still the same error when it reaches the server. Node handles the ‘data’ event and all is well until I try to parse the string, it causes an error undefined:1 unexpected o.

  • 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-01T14:03:00+00:00Added an answer on June 1, 2026 at 2:03 pm

    The data you’re sending is not valid JSON, which requires that all object keys are double-quoted.

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

Sidebar

Related Questions

EDIT: Just to make things clear, this problem was caused by a typo in
How to make a multi-thread python program response to Ctrl+C key event? Edit: The
I am looking for a tool which will make able to edit parts of
I don't want to do anything fancy, I just want to make sure a
Obviously, atomic operations make sure that different threads don't clobber a value. But is
I need to make sure users don't go to the download page unless they
I want to make sure I am testing Models/Objects in isolation and not as
I want to make a edit profile form for my website. My idea is
I use Zend framework to build the forms, I want to make the edit
Edit For simplicity: I just want to make the most basic possible cursor that

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.