无法获取任何已发布的JSON数据


Cant get any Posted JSON data?

UserStore将在数据存储更新时进行.sync,

var UserStore = Ext.create('Ext.data.JsonStore', {
        model: 'VehicleModel',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'get-vehicle.php',
            baseParams: {  //here you can define params you want to be sent on each request from this store
                        //groupid: 'value1',
                        },
            api: {
                    //create: 'update-vehicle.php',
                    //read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
                    update: 'update-vehicle.php',
                    //destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
                },
            reader: {
                type: 'json'
            },
            writer: {
                type: 'json'
             }
        }
    });

按下"保存"按钮时,将调用UserStore以使用update- vehicle.php 更新数据

var BtnSave = Ext.getCmp('BtnSave')
BtnSave.on('click', function(){
onButtonClick();    
})
function onButtonClick(){
           var grid = Ext.getCmp('mygridpanel')
           var row = grid.getSelectionModel().getSelection()[0];
           var txtVehicleID = Ext.getCmp('txtVehicleID').getValue();
           var txtPlat_No = Ext.getCmp('txtPlat_No').getValue();
           console.log(txtVehicleID);
            var record = UserStore.findRecord('_id', txtVehicleID);
            record.set('_id', txtVehicleID);
            record.set('Plat_No',txtPlat_No);
            UserStore.sync();
            console.log("clicked");
}
}); // on ready

这是我的FireBug Post Json数据,我看过

POST http://localhost/BusTicket/vehicle/update-vehicle.php?_dc=1386528763735
ParamsHeadersPostResponseHTML
JSON
Source
{"_id":"2","Plat_No":"AKC12342","id":null}

但是,我无法从我的php页面获取任何数据,这是我的update-vehicle.php页面,但可以获取任何数据。为什么?

<?php
echo $_POST['json'];
?>

更新

这是我的firebug响应头

Response Headers
Content-Length  0
Content-Type    text/html
Date    Mon, 09 Dec 2013 04:08:44 GMT
Server  Microsoft-IIS/5.1
x-powered-by    ASP.NET, PHP/5.3.15
Request Headers
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length  42
Content-Type    application/json; charset=UTF-8
Cookie  PHPSESSID=78peh3ahri6s0nfraldjden5k0
Host    localhost
Referer http://localhost/BusTicket/vehicle/vehicle.html
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:25.0) Gecko/20100101 Firefox/25.0
X-Requested-With    XMLHttpRequest

i echo $HTTP_RAW_POST_DATA html何时打印{"_id":"2","Plat_No":"AKC12341","id":null}

但我正在尝试使用$data = json_decode($HTTP_RAW_POST_DATA); echo $data;$数据再次为空。。。为什么?

问题是json数据是直接通过请求体发送的,而不是任何$_POST参数。您可以使用http_get_request_body()函数访问它,如下所示:

$data = json_decode(http_get_request_body());

使用以下代码解决的问题:-

<?php
$data = file_get_contents("php://input");
$obj = json_decode($data);
print $obj->{'Plat_No'}; 
?>

因为发布是原始数据,所以需要使用CCD_ 6或CCD_。