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

SOLVED: window.location.replace not working in JavaScript


Based on my Javascript code, window.location doesn't work after receiving true Response. However I've used possible ways to use it but it seems there's something wrong or maybe I'm doing wrong.

Here is my code:

$(function() {
var url = $(".url").val();
// start sign up functionality
$(".signupbtn").on('click', function() {
$('html, body').animate({
scrollTop: $(".toppage").offset().top - 100
}, 'slow');
function(response) {
if ($.trim(response) == 'true') {
} else {
// end signup functionality

In the THIS SECTION NOT WORKING which I mentioned in above, I've used all these following lines, but it doesn't work after true response:

  • window.location.replace(url);
  • window.location.href = 'url link';
  • window.location(url);
  • window.location.href = 'url Link'; return false;
  • window.location(url); return false;
  • window.location.replace(url); return false;
  • = '[url]'
  • = '[url]'; return false;
  • location.assign("url");
  • location = "url";
  • location.reload(true);

but In the THIS SECTION WORKS, all above and following lines codes works. I mean after else means response is false. ((I don't need it in false response but it works!!))

FYI, response False and True both of them works well.

Why I need this? Because after true response I need to reset form fields, for this issue, I also used these following lines, but again not working:

  • $('#headersignupform')[0].reset();

  • document.getElementById("headersignupform").reset();

  • $('form[name="headersignupform"]')[0].reset();

  • $("#headersignupform").get(0).reset();


I've solved the issue by adding response as HTML into JavaScript not through posted HTML from Ajax.

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: window.location.replace not working in JavaScript


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription