Skip to content Skip to sidebar Skip to footer

Reliably Complete Ajax Request On Page Unload

I have a html/javascript application. When user refreshes the page or close the page i need to make a ajax request and then close the application. I am using page unload event for

Solution 1:

$(window).on('beforeunload' function() {
    $.ajax({
        url: url,
        type: "GET",
        contentType: "application/json",
        async: false,
        crossDomain: true,
        dataType: 'jsonp',
        success: function(json){
          alert("success: " + json);
        },
        error: function(xhr, statusText, err) {
          alert("Error:" + xhr.status);
        }
    });
});

Try this....


Post a Comment for "Reliably Complete Ajax Request On Page Unload"