Hello! I'm trying to send some basic form data via a POST request.
The following works for me using jQuery's AJAX:
$.ajax({
type: 'POST',
url: 'api/form',
data: data,
dataType: 'json'
});
However the following does not work for me using fetch:
fetch('api/form', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: data
});
I have tried sending it both as JSON and as a serialized string, i.e. name=Brian&email=brian%40butterfield.com&message=Test+message, both give me the message contactForm.js:83 POST http://localhost:3000/api/form 404 (Not Found).
Any idea why this wouldn't be working?
I've attached screenshots of my network panel for both below:

Looks like I specifically needed the header 'X-Requested-With': 'XMLHttpRequest', seems to be working now!
鏌ョ湅涓媢rl
Most helpful comment
Looks like I specifically needed the header
'X-Requested-With': 'XMLHttpRequest', seems to be working now!