Get parameter passed by POST with $ .ajax [duplicate]

1

I'm having trouble getting the id passed by the date of the ajax (jquery), what happens is that using $_POST['id'] or filter_input(INPUT_POST,'id') is empty

follow ajax:

$.ajax({
    type:"POST",
    url: "cursos/area/",
    dataType:'JSON',
    data:JSON.stringify ({'id': idArea}),
    contentType: "application/json; charset=utf-8",
        success: function (result) {
            console.debug(result);
        }
})

And in PHP I'm just trying to display for testing

var_dump($_POST['id'])

I tried to find other ways to get past the date because I believe it was the problem, but nothing worked.

NOTE: no Request Payload id is right

    
asked by anonymous 26.12.2018 / 12:52

1 answer

1

I was able to solve it, I do not know if it's a good practice, but anyway, for anyone with the same problem:

$data=json_decode(file_get_contents('php://input'),1);
print_r($data['id']);
    
26.12.2018 / 13:01