PHP - file_get_contents ('php: // input') is the only way to read request contentType = application / json?

0

I have the following Jquery Ajax method

        function postRefreshJson(_action, jsonModel)
        {
            $.ajax({
                url: _action,
                method: 'POST',
                beforeSend: function (xhr) {
                    $("body").css("cursor", "progress");
                },
                contentType: 'application/json',
                data: JSON.stringify(jsonModel),
                success: function (r) {
                    console.log("success: " + r);
                    alert(r);
                },
                error: function (e) {
                    console.log("Erro: " + e);
                    alert("Erro: " + e.responseJSON.errorMessage);
                    $("body").css("cursor", "default");
                }
            });
        }

What I call something like this:

        var jsonModel = new Object();
        jsonModel.id = id;
        jsonModel.text = text;

        postRefreshJson("algumaUrl.php", jsonModel);

The only way I found to receive the contents of the above request was to use

 $jsonObj = json_decode(file_get_contents('php://input'), true);

Is there no way to access uploaded content? I Know It Using $ _POST?

I'm using application / json, but it's actually not very clear to me, what are the benefits of using it?

Yes, I would also like to know the implications of using:

  json_decode(file_get_contents('php://input'), true);
    
asked by anonymous 27.10.2018 / 15:11

0 answers