Got the following code running on a local wordpress install. I have created an application password for the admin user but am still getting a 401 unauthorised. What am i missing?
Here’s the code
jQuery.ajax({
type: "POST",
dataType: "json",
url: 'http://the-lead-magnet-company.local/wp-json/wp/v2/posts',
data: JSON.stringify({
title: me.title(),
content: 'Here is some content',
status: 'published'
}),
beforeSend: function ( xhr ) {
xhr.setRequestHeader('Authorization', 'Basic admin:DqfX r0YT hQE5 lsgu 2Y7d PJv5');
},
success: function (data) {
alert("posted");
},
error: function (error) {
alert("FAILD:" + error);
}
});