-1

I have a PHP file with multiple if statements where it checks if is set $_POST['something'] and returns specific data but when I try with ajax I can't get the data inside if statement because it isn't triggered to be true, here is what I am doing: From index.php I am sending a request to users.php like this

<script>
axios.post('users.php').then(data=>console.log(data)); // this returns status 200 but data is empty
</script>

and the users.php looks like this

if(isset($_POST['getusers']))){ return users;}

How can I make this to true isset($_POST['getusers']) by sending the request using Axios or fetch API? Note: There are other if statements inside the users.php file that's why I want to only get when a specific $_POST is set

Ray Pember
  • 13
  • 4

1 Answers1

-1

Try:


axios.post('users.php',{ getusers: true }).then(function (data) {
    console.log(data);
  });

Ron
  • 5,900
  • 2
  • 20
  • 30
  • not working still returned data is empty :( – Ray Pember Apr 28 '20 at 22:27
  • I updated my answer, please try now. – Ron Apr 28 '20 at 22:30
  • still the same, not working :( – Ray Pember Apr 28 '20 at 22:35
  • Outside axios, can you confirm that if you do a POST towards 'users.php' with `"getusers" = true` you are receiving the proper data you expect?? – Ron Apr 28 '20 at 22:36
  • Also you could share your PHP code, as `if(isset($_POST['getusers']))){ return users;} ` on it's own is wrong, it has one additional `)` at the end ... are you validating somehow your PHP code? any actual errors on the backend log? – Ron Apr 28 '20 at 22:38
  • I found the solution thanks for trying to help me, this is the reference where I found the solution https://stackoverflow.com/questions/41457181/axios-posting-params-not-read-by-post – Ray Pember Apr 28 '20 at 22:42