0

Requirement is to redirect from 'index.html' to 'userdetails.html' page on click of button (type = button)

I have 3 forms in index.html (each form to serve different purpose) All have method=Post.

In the second form, I have a button with type=button and id=userdetails, and onclick="sendDetails()"

Now function on same page:

function sendDetails(){
    $.ajax({
        method: "GET",
        url: "/newColl",
        success: function(data) {
            $('#form2').attr('action', '/userdetails');
        }

Now I have index.js page which has following function:

var createGroup = function(//<manipulation on mongodb>)

router.get('newColl', function(req, res, next){
    // mongo connection and calling createGroup function
    // this is working fine.
   client.close()
});

router.post('/userdetails', function(req, res, next) {
    res.redirect('userdetails.html');
}

I tried with res.redirect, res.sendFile, res.render, window.location.href(in html), but all in vain.

Please can anybody guide.

Thanks

gilly3
  • 87,962
  • 25
  • 144
  • 176
SKS
  • 7
  • 2
  • Possible duplicate of [How to manage a redirect request after a jQuery Ajax call](https://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call) – tbking Nov 29 '18 at 18:48
  • You mentioned 3 forms, but only described one (I assume "the second form" is `#form2`). Do the other two forms matter? The way it's coded, it looks like you want the user to click the button in `#form2` twice. Was that your intent? – gilly3 Nov 30 '18 at 01:00
  • Thanks...yes second form is #form2, the other forms have different purpose. In this second form, on click of button, I want to process some text search and result of that search to be stored in new field in new collection and once this is done..take it to next page where data will show from newly created collection. – SKS Nov 30 '18 at 15:34

0 Answers0