Im trying to send a post request with axios to php. Im a bit lost, still new to this stuff. in my react.js I have this. Im trying to send the value of searchTerm
axios.post(`http://www.fake.com/script.php`,{
searchTerm:'test',
})
.then(function(response){
console.log(response)
})
.catch(function(error){
console.log(error);
})
In the script.php file which I have hosted on my site, I have this:
if(!empty($_POST)) {
$searchTerm = $_POST["searchTerm"];
echo $searchTerm;
echo '<script>console.log('.$searchTerm.')</script>';
}
nothing is echoed on the actual page.
On the console, I have 3 things.
- XHR finished loading: OPTIONS "http://www.fake.com/script.php"
- data object, which includes config,data,headers,etc.
- XHR finished loading: POST "http://www.fake.com/script.php"
console.log(response)orconsole.log(error). Perhaps try giving them some labels to help identification, egconsole.log('response', response)andconsole.error(error)response.dataproperty. You haven't inserted it into your document and even then, it's not going to just execute the<script>blocks (see stackoverflow.com/q/1891947/283366)