Reputation: 93
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');
$.post("<?php echo base_url();?>account/signup",
$("#headersignupform").serialize(),
function(response) {
if ($.trim(response) == 'true') {
$(".resultsignup").html(response);
//THIS SECTION NOT WORKING
} else {
$(".resultsignup").html(response);
// THIS SECTION WORKS
}
});
});
// 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:
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();
Solution:
I've solved the issue by adding response as HTML into JavaScript not through posted HTML from Ajax.
Upvotes: 2
Views: 7337
Reputation: 21
Below code works like magic
window.history.pushState("", "", "new url"); window.location.reload();
Upvotes: 1
Reputation: 732
window.location work if you use code for example:
location.assign("http://www.mozilla.org"); // or
location = "http://www.mozilla.org";
You can look: https://developer.mozilla.org/en-US/docs/Web/API/Window/location
Upvotes: 2