Need Help with handling Json Object with PHP
Posted: Wed Nov 18, 2015 2:39 am
Hi, everyone, recently I try to handling json post request with php, below are my ajax code.
In my php , I got these code to handle the json, but I keep getting Trying to get property of non-object Error. Am I doing something wrong?
Code: Select all
var formData = {
"size_id" : 2,
"sizename" : some name
};
$.ajax({
type: 'post',
url: '<?= Yii::app()->createAbsoluteUrl('mypage/doUpdate') ?>',
dataType: 'json',
data: formData,
mimeType:"multipart/form-data",
contentType: false,
cache: false,
processData:false,
timeout: 120000,
success: function(data) {
// some function here ...
});
Code: Select all
$data = json_decode(file_get_contents('php://input'));
$size_id = $data->{'size_id'};
$sizename = $data->{sizename};