更新数据存储区时,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 Data
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
当我打印echo $HTTP_RAW_POST_DATA
html时
{"_id":"2","Plat_No":"AKC12341","id":null}
但我试图使用$data = json_decode($HTTP_RAW_POST_DATA); echo $data;
$数据再次为空......为什么?
答案 0 :(得分:2)
问题是json数据是通过请求体直接发送的,而不是任何$_POST
参数。您可以使用http_get_request_body()函数访问它,如下所示:
$data = json_decode(http_get_request_body());
答案 1 :(得分:0)
问题解决了以下代码: -
<?php
$data = file_get_contents("php://input");
$obj = json_decode($data);
print $obj->{'Plat_No'};
?>
因为发布是原始数据,因此需要使用file_get_contents("php://input");
或$HTTP_RAW_POST_DATA
才能获得发布数据。