0

如何在我的 wordpress 网站上获取并粉碎我在 php 中使用 sendbeacon 发送的 json 数据。我没有任何api。

我的代码;发送方;

window.addEventListener('unload', function() {
var params = JSON.stringify({
                    "s_id": "12469",
                    "e_id": "41213",
                    "v_lang": "en",
                    "time": "420.20",
                    "percent": "43.0",
                    "type": "keep"
                });
                                   
                    navigator.sendBeacon('http://localhost/ajaxservice/', params);

})

和客户端ajaxservice

 $json = file_get_contents("php://input");   
    $data = json_decode($json, true);

if(!empty($json)){ echo 'exist json!';}else{ echo 'no_exist' ;}

每次打印 no_exist :) 如何解决。谢谢。

4

0 回答 0