Make WordPress Core

Changeset 38425


Ignore:
Timestamp:
08/28/2016 06:28:52 PM (9 years ago)
Author:
iseulde
Message:

Editor: Use Beacon API over sync request

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/post.js

    r37303 r38425  
    408408        }
    409409
    410         $.ajax({
    411             type: 'POST',
    412             url: ajaxurl,
     410        var data = {
     411            action: 'wp-remove-post-lock',
     412            _wpnonce: $('#_wpnonce').val(),
     413            post_ID: $('#post_ID').val(),
     414            active_post_lock: $('#active_post_lock').val()
     415        };
     416
     417        if (window.FormData && window.navigator.sendBeacon) {
     418            var formData = new window.FormData();
     419
     420            $.each(data, function(key, value) {
     421                formData.append(key, value);
     422            });
     423
     424            if (window.navigator.sendBeacon(ajaxurl, formData)) {
     425                return;
     426            }
     427        }
     428
     429        // Fall back to a synchronous POST request.
     430        // See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
     431        $.post({
    413432            async: false,
    414             data: {
    415                 action: 'wp-remove-post-lock',
    416                 _wpnonce: $('#_wpnonce').val(),
    417                 post_ID: $('#post_ID').val(),
    418                 active_post_lock: $('#active_post_lock').val()
    419             }
     433            data: data,
     434            url: ajaxurl
    420435        });
    421436    });
Note: See TracChangeset for help on using the changeset viewer.