Ondemand javascript causes window unloading using jquery

I tried to bind "unload" and "beforeunload" in the following code, but none of the browsers send a request:

$(window).bind('unload', function(){
       $.ajax({cache: false,
        dataType: "script",
            url: "test.php"
        });
    });

Any suggestion?

+5
source share
2 answers

The browser did not wait for the completion of this code ... it works just fine :) Add alert('hi')to see how it works.

, , unload, , ... , , , . unload. , .

unload , , , DOM, , , , ( IE)... AJAX .

+6

async false.

$(window).bind('unload', function(){
   $.ajax({
    cache: false,
    async: false,
    dataType: "script",
        url: "test.php"
    });
});
+1

All Articles