0

I’m facing a situation with Ajax request on back button.

I created a form which posts values and returns results via ajax request according the given filters and loads on a specific div. When I click on any of the link on page, it opens the new url as expected. On clicking on browser back button it opens the previous form page with default values. How can I enable browser state functionality so that I have results with last posted values with browser back button. Note that type of ajax is POST.

One solution I got is that to modify this form type to GET instead of POST, but this would take much time to do changes in server side code.

var page_url = $(this).attr('href');
page_url = page_url.split(':');
var page = page_url['1'];

$form = $('#form);

        $.ajax({
        type: 'POST',
        data: $form.serialize(),
        url: webroot + 'controller /action/page:'+page
        }).done(function (result){
})

I want to know the possible solution.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Moyed Ansari
  • 8,226
  • 2
  • 33
  • 55

3 Answers3

2

You should set cache to false:

$.ajax({
    dataType: "json",
    url: url,
    cache: false,
    success: function (json) {...}
});

Source https://stackoverflow.com/a/25230377

Community
  • 1
  • 1
Roman Slobodzyan
  • 181
  • 1
  • 10
0

you can use Jquery .unload() function or try cookies you could read it from here How do I set/unset cookie with jQuery?

Community
  • 1
  • 1
Þaw
  • 1,969
  • 2
  • 19
  • 37
0

Once you submitting that time dont go for new page, just hide the form elements and display new content in other div. Once you click on back button just show previously hidden div and hide current showing div

mathew
  • 143
  • 1
  • 5
  • I cant load new content on same page because this has separate views. and I cant use hide/show for every view that open with new links – Moyed Ansari May 02 '13 at 07:32