0

I want to send an object to a php file using XMLHttpRequest.

function sendAjax(url, data){
  const request= new XMLHttpRequest();
  request.open('POST',url, true);
  request.setRequestHeader("Content-Type","application/json");
  request.onreadystatechange=function(){
    if(request.readyState!==4 || request.status !==200){
      return;
    }
    const response= JSON.parse(request.response);
    console.log(response);
  }
  request.send(JSON.stringify(data));
}

sendAjax('./postWork/removePost.php',{id})
  $id=(int) $_POST['id'];
  exit(json_encode($_POST));

At the output I get

[]

What is the problem?

0 Answers0