Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

GET not redirecting the page nodeJS/mongo

GET not redirecting the page nodeJS/mongo

Problem

I have a POST that is an ajax post based on a button and the form has it's own post. Every time the button is Clicked a post is made but it does not redirect to the userProfile Page even tho it is calling a get for it and returning a 304 for it.

Here is the script file:

 $('.removeEmail').click(function() {
        $.post('/removeEmailPost', {userE: $(this).data('user')});
        });   

Here is the routes file:

exports.newEmailPost = function(req, res) {
    if(req.body.emailNew === '') {
        console.log('blank');
        res.redirect('editUserProfile');
    } else {
        User.findByIdAndUpdate(req.signedCookies.userid,{
            $addToSet: {emailList: req.body.emailNew}
        }, function(err, userX) {
            if(err) {
                console.log(err);

            } else {

                res.redirect('userProfile');
            }       
            console.log(userX);
        });     
    }

};
Problem courtesy of: Lion789

Solution

Add a type="button" attribute to your , so it doesn't auto-submit the form when clicked.

Solution courtesy of: antishok

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

GET not redirecting the page nodeJS/mongo

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×