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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:53:11+00:00 2026-06-04T08:53:11+00:00

I made a chrome extension which calls jQuery’s ajax method: content-script.js […] $.ajax({ url:

  • 0

I made a chrome extension which calls jQuery’s ajax method:

content-script.js

[...]
$.ajax({
    "url": "http://localhost:5000/",
    "type": "PUT",
    "contentType": "application/json",
    "data": { "name": "random object" },
    "dataType": "json"
});
[...]

On the server side, I’m trying to fetch the information passed in the data attribute:

web.js

[...]
app.put('/', function(request, response) {
    console.log(request.data);
});
[...]

But I’m getting undefined instead. How is the object passed in the data attribute supposed to be retrieved on the server side (Node.js + express.js)?

I also tried console.log(request) and got a LOT of stuff in there, but nothing that looked like the info I passed along in the data attribute…

EDIT

My latest attempt (based on graydsl’s answer) brings the following changes to the code above:

  • Added app.use(express.bodyParser()); just before app.put....
  • Changed put to post everywhere
  • Changed request.data to request.body.data

Now, the code does what I want when responding to a form like this:

<form method="post" action="/">
    <input name="data" type="text" value="WOO HA" />
    <input type="submit" name="submit" value="submit" />
</form>

However it still fails if I revert to using post instead of put (and the browser ends up on http://localhost:5000/?data=WOO+HA&submit=submit for some reason)

It also fails when putting (or posting) with ajax (see code above). When I try it with ajax, I get this on the server:

SyntaxError: Unexpected token ILLEGAL
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/home/shawn/.node_libraries/.npm/connect/1.8.7/package/lib/middleware/bodyParser.js:135:16)
    at IncomingMessage.emit (events.js:61:17)
    at HTTPParser.onMessageComplete (http.js:133:23)
    at Socket.ondata (http.js:1019:22)
    at Socket._onReadable (net.js:683:27)
    at IOWatcher.onReadable [as callback] (net.js:177:10)
  • 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-04T08:53:12+00:00Added an answer on June 4, 2026 at 8:53 am
    1. As others have mentioned, and you’re now doing, you need to use the bodyParser` middleware.

    2. If the request body has a content type of “application/json”, bodyParser will parse it into an object, which will be located at request.body. Thus in your case request.body.name should be “random object”.

    I think you (and several of the previous responders) are mentally hanging up on the fact that jQuery’s ajax method uses the key name “data” for an object to be sent (serialized as JSON) in the request body, and magically sliding to the assumption that anything on the server side that processes the request will also call that object by the name of “data”. There’s no connection between the two.

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

Sidebar

Related Questions

I have made a Google Chrome extension which mimics the Internet Explorer favorites drop-down.
I'm using the following script within a Chrome extension I made. It replaces old
This issue drove me nuts for 2 days. I made a simple chrome extension
I am experiencing some problems with a google chrome extension I have made. I've
I've made a Chrome extension with an options page. The data is saved in
i made a chrome extension, and my extension will show popup on webpage. I
I want to study the changes made to Google Chrome's source code which is
I have made an AJAX chatroom; and it works in chrome and FF, but
I made an extension for google chrome but I don't like what the market
I just made a Chrome extension. I followed this tutorial to get a nice

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.