Get parameter passed by POST with $.ajax

Asked

Viewed 53 times

1

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

follow the 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 simply trying to display to test

var_dump($_POST['id'])

I tried to find other ways to pass the date, because I believe to be the problem, but nothing worked.

NOTE: no Request Payload id is right

inserir a descrição da imagem aqui

  • Pq is using this way: data:JSON.stringify ({'id': idArea}), when you could use it like this: data: {id: idArea},?

  • @Sam actually I was testing several ways, it turned out that when I asked the question was sssim

1 answer

1


I managed to solve, I do not know if it is a good practice, but anyway, for those with the same problem:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.