Parse Javascript fetch in PHP

前端 未结 3 1659
無奈伤痛
無奈伤痛 2021-01-01 19:11

I\'m calling a post request through Javascript and here\'s how it looks,

function syncDeviceId(deviceID, mod){
  var request = new Request(\'url\', {
    met         


        
3条回答
  •  独厮守ぢ
    2021-01-01 19:53

    I too was having the same issue.

    I used Chrome debug tool first to make sure that I was passing on a Request Body (Which the chrome debug will call "Request Payload") I was sending

    {ClientDomain: "example.com"}
    

    I then used the stated code in my receiving PHP script.

    $json = file_get_contents('php://input');
    $data = json_decode($json);
    

    which then put my JSON code into an array which I could then read in PHP.

    PRINT $data["ClientDomain"];
    

    I hope this helps the next guy.

提交回复
热议问题