This ajax has an action that can be used to run function and access the data values as $_POST['mydata']
in the callback function
$.ajax({
url: qrAjax.ajax_url,
type: 'POST',
context: this,
data: {
action: 'qrcode_post_create',
nonce: qrAjax.nonce,
mydata : datas,
},
success: function(response) {
alert("Success");
$(".qrresponse").append(response);
},
});
Is there a way to do a similar thing with fetch()?
fetch('https://mywebsite.online/wp-json/wp/v2/qrcode', {
method: 'POST',
credentials: 'same-origin',
headers: new Headers({
'Content-Type': 'application/json;charset=UTF-8',
'X-WP-Nonce' : qrAjax.nonce
}),
body: JSON.stringify(OurPostData),
}).then(response => {
console.log(response);
return response.json();
}).then(data => console.log(data));
question from:https://stackoverflow.com/questions/65644434/fetch-post-request-actions