In case you are using any client-side JavaScript framework, authorization headers can be sent for the desired interaction with WP API. The DELETE
request would then be sent by another jQuery.ajax()
method like this:
$.ajax({ url: 'http://something/wp-json/wp/v2/posts/25', method: 'DELETE', crossDomain: true, beforeSend: function ( xrh ) { xrh.setRequestHeader( 'Authorization', 'Basic ' + Base64.encode( 'username:password' ) ); }, success: function( data, txtStatus, xrh ) { console.log( data ); console.log( xrh.status ); } });
In this example, the BASE64
is considered to be an object used for encoding a string.
This is a way of cross-browser encoding of a string within JavaScript.
The Authorization
header was used in the preceding example, and the setRequestHeader()
method within xhr
object was passed as an argument to the beforeSend...