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

View File

@ -407,16 +407,31 @@ jQuery(document).ready( function($) {
return; return;
} }
$.ajax({ var data = {
type: 'POST', action: 'wp-remove-post-lock',
url: ajaxurl, _wpnonce: $('#_wpnonce').val(),
async: false, post_ID: $('#post_ID').val(),
data: { active_post_lock: $('#active_post_lock').val()
action: 'wp-remove-post-lock', };
_wpnonce: $('#_wpnonce').val(),
post_ID: $('#post_ID').val(), if (window.FormData && window.navigator.sendBeacon) {
active_post_lock: $('#active_post_lock').val() 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
}); });
}); });