title: Nodejs - update user password from a boostrap form with ajax
body: <p>I'm trying to let the user update their password without reloading the page but I keep getting <code>POST /user?userid=something 404</code> error. Can anyone spot what I did wrong? Thanks.</p>
  
  <p>Bootstrap modal</p>
  
  <pre><code>       &lt;form method="post"&gt;
              &lt;div class="modal-body"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label for="password"&gt;New password&lt;/label&gt;
                          &lt;input type="password" class="form-control" name="password" id="password" placeholder="Password" onkeyup='checkPassword();' required&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label for="confirmPassword"&gt;Confirm new password&lt;/label&gt;
                          &lt;input type="password" class="form-control" id="confirmPassword" placeholder="Re-enter your password" onkeyup='checkPassword();' required&gt;
                          &lt;span id='message'&gt;&lt;/span&gt;
                      &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;button type="button" class="btn btn-secondary" data-dismiss="modal"&gt;Close&lt;/button&gt;
                  &lt;button id="submit" type="submit" class="btn btn-primary" disabled&gt;Save changes&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>ajax script</p>
  
  <pre><code>&lt;script&gt;
  $(function(){
      $('#submit').on('submit', function(e){
          e.preventDefault();
          var new_password = $('#password').val();
          $.ajax({
              url: '/user',
              type: 'post',
              data: new_password,
              success: function(data){
                  alert(data)
              }
          });
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>index.js - server side</p>
  
  <pre><code>router.post('/user'), function (req, res) {
      User.updateOne({ '_id' :  req.query.userid }, {$set: {password: createHash(req.body.password)} });
  }
  </code></pre>