jquerydrupal-7drupal-ajax

location.reload() in site's frontend is interferring with site's admin backend


Here's my code:

// Reload screen after submission and completion of AJAX actions
$('.view-whiteboard, .view-whiteboard-full').ajaxStop(function() {
  location.reload();
});

I have this code operating in the frontend of my Drupal website but for some reason when I submit/save anything in the backend admin panel the above snippet of code makes the page reload.

I'm confused as to why it's doing this since I have defined the class names in the code that should be specific to the forms in the frontend.

Am I missing something in my above code that's making it so I'm triggering location.reload() on every form submission?

Any help would be great. Thanks--


Solution

  • As of jQuery 1.8, the .ajaxStop() method should only be attached to document. You can get around this by creating a .click function that runs ajaxStop once:

    $(document).ready(function(){
        $(".view-whiteboard, .view-whiteboard-full").click(function(){
            $(document).one("ajaxStop", function() {
                location.reload();
            });
        });
    });
    

    Otherwise, just separate the public vs admin theme so that they don't use the same javascript (must disable overlay module).