Sunday 14 May 2017

after ajax post, GET isn't working node js

So, after my ajax is firing up I get a value that I need in server side.

  $('.MyForm').on('submit', function(event){
    event.preventDefault();
    var createVar = $(this).find(".lessonText").html();

    $.ajax({
      url: '/qVal',
      method: 'post',
      dataType: 'text',
      data: {'desc':createVar},
      async: true,
      success: function(data){

      }
    })


  });

Here I am assigning to a variable and now I want to redirect from that point to another page.

router.post('/qVal', function(req,res){  
    SSN3 =req.session;
    SSN3.description = req.body.desc; 
    console.log(SSN3.description);
    return res.redirect('/questions');

});

router.get('/questions', function(req,res, next){
    res.render('questions');    
});

I know that I can redirect to another page by using window.location.href after ajax function is success but I want to do that from server side. The weirdest part that after post, get is firing up but it doesn't work. http://i.imgur.com/2K5kDaY.png



via pim88

No comments:

Post a Comment