Click here to Skip to main content
15,921,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using ajax (XmlHttpRequest) on Chrome does not work anymore as indicated on the link below:
https://www.chromestatus.com/feature/4664843055398912

So this site below suggest to use sendBeacon instead:
https://medium.com/@oahehc/synchronous-xmlhttprequest-failing-in-chrome-73-c7537f8156a3

However, the web service does not execute based on the code below. Is there any way to execute the web service. It is much better if the scope of the solution only limits on the used language below.

What I have tried:

I use web service to execute a function:
C#
[WebMethod]
public string CheckOutUser(string id)
{
    return "OK";
}

On the .js file, I have the following code:
JavaScript
$(function () {
    window.onbeforeunload = checkOutUser;
})

function checkOutUser() {
    var url = "TrascriptionService.asmx/CheckOutUser";
    var data = new FormData();
    data.append('id', userId);

    var result = navigator.sendBeacon(url, data);
}
Posted
Comments
Richard Deeming 15-Feb-21 11:47am    
Is the userId variable defined somewhere, and does it contain the expected value?

Is the URL correct?

Does sendBeacon return true?

Are there any errors or warnings logged in the developer console? (You may need to turn on "Preserve log upon navigation" to see the entries.)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900