title: AJAX Post request - sending json object to node.js server
body: <p>I am making an Ajax Post request:</p>
  
  <pre><code>$.ajax({
          type:"POST",
          dataType:"json",
          contentType: "application/json",
          data:newWorkLog,
          url:"/add",
        })
          .done(function(response){
            console.log("Response of update: ",response)
          })
          .fail(function(xhr, textStatus, errorThrown){
            console.log("ERROR: ",xhr.responseText)
            return xhr.responseText;
          });
  </code></pre>
  
  <p>and was expecting to pass that <code>newWorkLog</code> object to an API method through my node.js server:</p>
  
  <pre><code>var bodyParser = require('body-parser');
  app.use(bodyParser.json())
  
  app.post('/add', function(req, res){
          console.log(req.body) //This doesnt output anything
          res.send(JSON.stringify(req.body));
      });
  </code></pre>
  
  <p>After trying some approaches, I decided to only check what is being sent to my server.</p>
  
  <p>Doing this, the message I get is:</p>
  
  <pre><code>SyntaxError: Unexpected token # in JSON at position 0
      at JSON.parse (&lt;anonymous&gt;)
      at createStrictSyntaxError (C:\working\app\node_modules\body-parser\lib\types\json.js:157:10)
      at parse (C:\working\app\node_modules\body-parser\lib\types\json.js:83:15)
      at C:\working\app\node_modules\body-parser\lib\read.js:121:18
      at invokeCallback (C:\working\app\node_modules\raw-body\index.js:224:16)
      at done (C:\working\app\node_modules\raw-body\index.js:213:7)
      at IncomingMessage.onEnd (C:\working\app\node_modules\raw-body\index.js:273:7)
      at emitNone (events.js:106:13)
      at IncomingMessage.emit (events.js:208:7)
      at endReadableNT (_stream_readable.js:1055:12)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickCallback (internal/process/next_tick.js:180:9)
  </code></pre>
  
  <p>When I  console.log my <code>newWorkLog</code> object, I can see from my client side, the correct json object.</p>
  
  <p>when I check the param on the console I see the request payload and it looks like:</p>
  
  <pre><code>user%5Bid%5D=109&amp;user%5BuserName%5D=myname
  </code></pre>
  
  <p>What could be causing that error?</p>