Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows.history.back() + location.reload() jquery

Tags:

I've a probleme in my code. The aim is to complete a simple form, then you click on a submit button. It do an Ajax resquest to go in the method. On success in the ajax request, i use windows.history.back() to go to the previous page ans here i want to refresh this page, to refresh values which are modificated by the form ! Have you an idea about that ?

    $('#form_edit').submit(function (e)     {         e.preventDefault();         $.ajax({             url: $('#form_edit').attr('action'),             type: 'POST',             cache: false,             data: $(this).serialize(),             success: function (data) {                 if (data === true) {                     alert("Modification réussie !");                     window.history.back();                     location.reload(); <= on success i want to refresh previous page                 }                 else {                     alert("Modification échouée !");                 }             },             error: function ()             {                 alert("Modification échouée !");             }         })     }) 
like image 226
Julien698 Avatar asked Sep 03 '14 08:09

Julien698


People also ask

What is the difference between location reload () and window location reload ()?

location. reload(true); reloads the page from the server instead of from the cache, window. location. reload(); would do the same thing as location.

What is location reload in jQuery?

Window location. The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.

What is location reload ()?

The location. reload() method reloads the current URL, like the Refresh button.

Can I use window location reload?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.


2 Answers

window.history.back(); Sometimes it's an issue with javascript compatibility with ajax call or design-related challenges.

I would use this below function for go back with the refresh.

function GoBackWithRefresh(event) {     if ('referrer' in document) {         window.location = document.referrer;         /* OR */         //location.replace(document.referrer);     } else {         window.history.back();     } } 

In your html, use:

<a href="#" onclick="GoBackWithRefresh();return false;">BACK</a>` 

For more customization you can use history.js plugins.

like image 155
Sender Avatar answered Nov 16 '22 16:11

Sender


This is the correct answer. It will refresh the previous page.

window.location=document.referrer; 
like image 32
Inamur Rahman Avatar answered Nov 16 '22 15:11

Inamur Rahman