1

I am trying to make use of the hash symbol to enable back-button and refresh functionality in my AJAX web app.

In Firefox and Chrome when I click refresh the browser reloads everything properly and when the script below is run a new request is made using the URL that appears after the # sign.

In IE8 the request is never made during a refresh, however the alert pops up as if it has! I can reproduce this behavior in this simplified HTML document which I posted here:

Full HTML Doc http://pastebin.com/CVySwtup

Sample Code

$(document).ready(function () {
    // 1. AJAX history & back button
    $(window).bind("hashchange", function (e) {
        if (!ignoreHashChange) {
            // Load content
            $("#content").load(location.hash.substring(1), function () {
                alert("content loaded!");
            });
        }
        ignoreHashChange = false;
    });

    // 2. Home page / refresh action
    if (location.hash) {
        $(window).trigger("hashchange");
    } else {
        location.hash = "Customers/List";
    }
});

edit: same behavior in IE8 when using $.get()

Jeff Camera
  • 5,324
  • 5
  • 44
  • 59

1 Answers1

2

IE is probably reading the content from its local cache. See jQuery's .load() not working in IE - but fine in Firefox, Chrome and Safari for details and workarounds.

Community
  • 1
  • 1
SpliFF
  • 38,186
  • 16
  • 91
  • 120