0

I'm using react as my frontend and php as a backend

i made a function that send the selected items in array to php but it seems broken

thats my react code

const deleteBtn = async () => {
    if(selectedProducts.length >= 1){
        const sendData = await axios.post("http://localhost/php/index.php",JSON.stringify({
        items:selectedProducts  //-----> selectedProducts = ["GGWP0008","GGWP0009","GGWP0010"]
      }))
    }
  }

thats my php code

header('Access-Control-Allow-Origin: http://localhost:3000');
    if($_SERVER["REQUEST_METHOD"] === "POST"){
        print_r(json_decode($_POST, true));
        $_POST = json_decode(array_keys($_POST)[0], true); // to decode the incoming json request
        print_r($_POST); ----> shows some weird formated string 
    }

the result of print_r before decode it shows

Array
(
    [{"items":] => Array
        (
            ["GGWP0008","GGWP0007"] => 
        )
Mark Wasfy
  • 167
  • 1
  • 13

0 Answers0