Made other modification to the code. I think I'm closer than ever but
I'm at a loss as to what to do next. I got rid of the redirection
statement, opting instead to replace the content on the page
dynamically using an ajax request. It seemed to help, now 'reinstate'
is defined every  time the back button is clicked, however I can't get
any data from it. It just says the data is undefined every time. Any
help fixing it would be greatly appreciated.

new code:

$.history.callback = function (reinstate, cursor) {
//      alert('history called back');
        // reinstate if not back at beginning
//      alert('callback: ' +  reinstate.agentBrowserHTML);
        if (typeof(reinstate) == 'undefined')
        {
                alert('reinstate undefined');
        }
        else {
                alert(reinstate.oldContent);
//              $('.content').html(reinstate.preViewUser);
        }
};

the following function is called when I want to view a user page, this
is the point at which I need to save the page state so when the user
clicks the back button after viewing a user I can restore the page the
same as it was just before the user was viewed. I checked to make sure
'oldContent' was defined by using an alert box to display it before
calling $.history.

function viewUser(user) {
        var oldContent = $('.content').html();
        $.history({"oldContent": oldContent});
        $.get('index.php?action=view_user', {user: user}, function(new_html)
{
                $('.content').html($('.content', new_html).html());
        });
}

On Mar 4, 2:05 pm, NightWatchman <rushi...@gmail.com> wrote:
> I'm making a website that has a drill-down form in it where you can
> select an office from a dropdown and then an agent from that
> particular office. My problem is once the user views an agent and
> clicks the back button on the browser my page breaks. I need to retain
> some page states in the form of HTML markup so that when the user
> clicks the back button on the browser I can show them the same page
> state they were looking at. After the intial page load all the new
> content is provided using Ajax post calls. It seems to me thatjHistorywould 
> be perfect for doing this but unfortunately in the
> $.history.callback function there doesn't seem to be any valid
> reinstate object to get the old data from. Can anybody help me figure
> out why? Here is my code.
>
> $.history.callback = function(reinstate, cursor) {
>         alert('history called back');
>         // reinstate if not back at beginning
>         if (typeof(reinstate) != 'undefined') {
>                 $('#AgentBrowser').html('called back browser');
>         }
>         else {
>                 alert('reinstate undefined');
>         }
>
> };
>
> and the function where the history object is instantiated...
>
> function attachFormEventHandlers() {
>         // office_id
>         $('#office_id').change(function() {
>                 
> $.post('index.php?action=addon_agentsearch_get_new_office_html',
>                                                 {office: $(this).val()}, 
> function(new_html) {
>                         var new_browser = $('#AgentBrowserHTML', 
> new_html).html();
>                         ...some unrelated code...
>                         // update agent browser
>                         $('#AgentBrowser').html(new_browser);
>                         // retain browser state
>                         $.history({'agentBrowserHTML':new_browser});
>                         // retain last form action in page so that when the 
> user
>                         // pages through the agents it can re-build the agent 
> list
>                         $('#Control').val('office_id');
>                 });
>         });
>
> }
>
> When the page is run and the back button is clicked on the browser
> after viewing an agent the $.history.callback function alerts that
> reinstate is undefined and the page content does not get changed.

Reply via email to