I have been trying to figure this out all afternoon, but have given up and now turning to you clever people to help :)
I have the following Jquery/Javascript functio
Just for anyone having the same issue, the problem was because the window.location was inside the Ajax post method.
Just replace the window.location with a function() that then calls the window.location or do it after the Ajax call completely.