PUT on Tab Close Doesn't Complete

51 Views Asked by At

On close of a browser tab, I'm attempting to do an automatic save of the user's changes. I have verified this works at other points in the timeline; the same function is used. I call it in the unload handler:

$( window ).unload(function() {        
    saveAnnotations(pdfState.pdfs[pdfState.activePdfIndex].PdfPages[pdfState.activePageIndex]);
});

Saving the user's changes involves a RESTful PUT inside that saveAnnotations function, using the Oboe library:

oboe({
  url: configuration.rootApiUrl + 'PdfPages/' + page.ID,
  method: 'PUT',
  body: page
}).done(function(jobs) { // Our call does not provide a callback
  if(callback !== undefined && _.isFunction(callback)) {
    callback();
  }
});

The server receiving this is a Microsoft Web API server. I'm running both the client and the server locally for testing.

In diagnosing this I edited the above code in place to be a GET rather than a PUT, and it hit a breakpoint inside the route on the server. However, when doing a PUT, I do not hit the breakpoint inside that server route on tab close. Why would it work for a GET and not a PUT? What must I do so that the server can receive my PUT? My hunch is that it is client side, not server side. If it would be helpful to see the server route I can post that, but otherwise I don't want to clutter the question.

0

There are 0 best solutions below