title: Send Json data and redirect using Jquery and node js
body: <p>I have the following page as shown below:<a href="https://i.stack.imgur.com/j9CyD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j9CyD.png" alt="enter image description here"></a></p>
  
  <p>When I click on the edit button, I want the send the id of button to my node JS server which will redirect me to the following webpage:
  <a href="https://i.stack.imgur.com/abD1t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/abD1t.png" alt="enter image description here"></a></p>
  
  <p>And also my Node JS server will send back the JSON data to fill up the form in the following page. The problem I am facing is that whenever I click the button, my page is not redirected.
  The following jquery code sends an ajax call:</p>
  
  <pre><code>$("#viewAllContest button").click(function () {
  //console.log($(this).attr('id'));
  var id = $(this).attr('id');
  $.ajax({
      type: 'POST',
      url: '/contests/redirectContest',
      data: JSON.stringify({id:id}),
      success: function(data) { console.log('success')},
      contentType: "application/json",
      dataType: 'json'
      });
  });
  </code></pre>
  
  <p>Then my routes in Node JS app receives the request and should redirect the page:</p>
  
  <pre><code>router.post('/redirectContest',function (req,res) {
  var id = req.body.id;
  console.log(id);
  res.redirect('/contests/viewContest');});
  </code></pre>
  
  <p>I have even added <code>return res.redirect('/contests/viewContest');</code> but it does not redirect my webpage. The code to render viewContest is:</p>
  
  <pre><code>router.get('/viewContest',ensureAuthenticated,function (req,res) {
  
  res.render('viewContest');});
  </code></pre>
  
  <p>I would be grateful if someone can guide me as to where I am going wrong here.</p>