Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to use <code>req.body.data</code>. Something like this should work:</p> <pre><code>app.post('/', function(req, res) { console.log(req.body.data); res.redirect('/'); }); </code></pre> <p>Take a look at this link: <a href="http://www.senchalabs.org/connect/bodyParser.html" rel="nofollow">bodyParser</a></p> <p>I hope I could help you! :)</p> <p><strong>EDIT:</strong> Just found a nice lib for working with $.ajax, it's called: <a href="https://github.com/visionmedia/superagent" rel="nofollow">superagent</a>. You might consider giving it a try. Looks promising. :)</p> <h1>Update</h1> <p>The problem lies in your jquery code not in the node.js code. You can't send an object in the <code>data</code> property of the <code>settings</code> object, you have to <em>stringify</em> the data object first. You can use the <code>json2.js</code> from the awesome <em>D - to the - ouglas Crockford</em>: <a href="https://github.com/douglascrockford/JSON-js" rel="nofollow" title="json2 Link">json2.js</a></p> <p>After you included that library the following code should give you the result you want:</p> <pre><code>$().ready(function() { var data = { data: "My name is", name: "Slim Shady" }; stringifiedData = JSON.stringify(data); $.ajax({ "url": "http://127.0.0.1:3000/", "type": "PUT", "contentType": "application/json", "data": stringifiedData, "dataType": "json" }); }); </code></pre> <p>And in the app.js:</p> <pre><code>app.put('/', function(req, res) { console.log(req.body.data + "... " + req.body.name); res.redirect('/'); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload