handle json request in PHP
Posted
by wo_shi_ni_ba_ba
on Stack Overflow
See other posts from Stack Overflow
or by wo_shi_ni_ba_ba
Published on 2010-06-17T16:56:20Z
Indexed on
2010/06/17
17:03 UTC
Read the original article
Hit count: 291
When making an ajax call, when contentType is set to application/json instead of the default x-www-form-urlencoded, server side (in PHP) can't get the post parameters.
in the following working example, if I set the contentType to "application/json" in the ajax request, PHP $_POST would be empty. why does this happen? How can I handle a request where contentType is application/json properly in PHP?
$.ajax({
cache: false,
type: "POST",
url: "xxx.php",
//contentType: "application/json",
processData: true,
data: {my_params:123},
success: function(res){
},
complete: function(XMLHttpRequest, text_status) {
}
});
© Stack Overflow or respective owner