Editor: Use Beacon API over sync request

See https://www.w3.org/TR/beacon/ for more information.



git-svn-id: https://develop.svn.wordpress.org/trunk@38425 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2016-08-28 18:28:52 +00:00
parent 16bb82eb76
commit 99bc5e7fb6
1 changed files with 24 additions and 9 deletions

View File

@ -407,16 +407,31 @@ jQuery(document).ready( function($) {
return;
}
$.ajax({
type: 'POST',
url: ajaxurl,
async: false,
data: {
action: 'wp-remove-post-lock',
_wpnonce: $('#_wpnonce').val(),
post_ID: $('#post_ID').val(),
active_post_lock: $('#active_post_lock').val()
var data = {
action: 'wp-remove-post-lock',
_wpnonce: $('#_wpnonce').val(),
post_ID: $('#post_ID').val(),
active_post_lock: $('#active_post_lock').val()
};
if (window.FormData && window.navigator.sendBeacon) {
var formData = new window.FormData();
$.each(data, function(key, value) {
formData.append(key, value);
});
if (window.navigator.sendBeacon(ajaxurl, formData)) {
return;
}
}
// Fall back to a synchronous POST request.
// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
$.post({
async: false,
data: data,
url: ajaxurl
});
});