0

I add a class to the button after an ajax request, so that the button gets a different color. If i click something on the site and go back, than the new class, added by toggleClass, is gone. The Browser shows probably not the changed DOM, but the original from the first page load. Heres my code.

$('.toogleUser').click(function() {
    var event_id = $(this).val();
    $(this).toggleClass("active");
    $.ajax({
        url: "/add/",
        type: "POST",
        data: {
            event_id: event_id
        },
        cache: false
    }).done(function(msg) {
        $.ambiance({message: msg, type: "success"});
    });
});

Edit: the first demo on the jquery doc keeps there class attribute: http://api.jquery.com/toggleClass/ If you highlite a paragraphe, then click on a link and turn back, the paragraphes still keeps the "highlite" class.The code use nothing except toogleClass. Why does my code work not like this from the demo?

PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
YYYY-MM-DD
  • 4,411
  • 1
  • 15
  • 14
  • 5
    This is by design. You will need to store the user state either in a browser store (http://stackoverflow.com/questions/2689939/html5-database-storage-sql-lite-few-questions) or on the server-side in a store of your choice. Then you will need to query that on your page load. – Justin Helgerson Dec 21 '12 at 01:07
  • either store the state in a cookie or local storage. HTTP is stateless – Ryan Dec 21 '12 at 01:41
  • Yeah, but the first demo on the jquery doc keeps there class attribute: http://api.jquery.com/toggleClass/ If you highlite a paragraphe, then click on a link and turn back, the paragraphes still keeps the "highlite" class. – YYYY-MM-DD Dec 21 '12 at 01:55
  • None of the demos keeps its state when I click a link and then the browser back button. – John Dvorak Dec 21 '12 at 05:45
  • Firefox keeps the state, chrome does it not. – YYYY-MM-DD Dec 21 '12 at 14:51

0 Answers0