Answer the question
In order to leave comments, you need to log in
How to submit a form using fetch, process in php and return a response?
Actually, a method is written in React that is executed as soon as the user submits the form:
handleSubmit(e){
e.preventDefault();
let callBack = new FormData(e);
fetch('http://127.0.0.1', {
method: 'POST',
headers: {
"Content-Type": "multipart/form-data"
},
body: callBack
}).then(res => res.json()).then((result) => {console.log('Result = ' + result)}, (error) => {console.log('Error = ' + error)});
}
<?php
$data = $_REQUEST["callBack"];
print_r($data);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question