John Walker
John Walker

Reputation: 1121

Cant get any Posted JSON data?

UserStore will .sync when the datastore are updated,

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'

             }
        }
    });

when pressed the Save button, will call the UserStore to update the data with 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

this is my FireBug Post Json Data i have seen

POST http://localhost/BusTicket/vehicle/update-vehicle.php?_dc=1386528763735
ParamsHeadersPostResponseHTML
JSON

Source
{"_id":"2","Plat_No":"AKC12342","id":null}

But, i can't get any data from my php page, this is my update-vehicle.php page, but get anything. Why?

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

UPDATE

this is my firebug response header

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

when i echo $HTTP_RAW_POST_DATA html will print {"_id":"2","Plat_No":"AKC12341","id":null}

but i m trying to use $data = json_decode($HTTP_RAW_POST_DATA); echo $data; $data is blank again...why?

Upvotes: 1

Views: 165

Answers (2)

John Walker
John Walker

Reputation: 1121

Problem Solved with this following code :-

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

because posting are raw data so need to use file_get_contents("php://input"); or $HTTP_RAW_POST_DATA only can get the post data.

Upvotes: 0

Maciej Sz
Maciej Sz

Reputation: 12045

The thing is that the json data is send directly through request body, not any $_POST param. You can access it using http_get_request_body() function like this:

$data = json_decode(http_get_request_body());

Upvotes: 2

Related Questions