在extjs4,如何添加一个记录到数据库?php如何接收由post方法翻译的ajax数据(json格式)的数据


in extjs4, how to add a record to database? How php can received the data from ajax data(json format) translated by post method?

php如何接收由post方法翻译的ajax数据(json格式)的数据?
我只是希望客户端可以通过ajax方法将数据从客户端发送到服务器,以json作为数据格式。

下面是我的代码,//行我可以在存储上添加数据,但数据不能添加到数据库上javascript:


    AddBtnClick: function(btn, event){
    var friendstore= this.getGrid().getStore();
    var grid = Ext.ComponentManager.get('searchfriendgrid');
    var selModel = grid.getSelectionModel();
    if(!selModel.hasSelection()){
        Ext.Msg.alert('', '');
    }else{
        //var store = grid.getStore();
        var record=selModel.getLastSelected();
friendstore.add(record); //
} formpanel.close(); /////////////////** }
php:


    public function jsonCreateFriendAction() {
    print_r($_POST['data']);
    print_r($_POST['data']['friendname']);
    //in reality here is some database action, 
    //I find my backend do not received any data from my from end
    //print nothing here
    }

邮件到达服务器了吗?您可以使用firebug查看网络流量

如果没有指定的post变量,可以使用

$data = file_get_contents("php://input"); 

获取发布的数据,然后

$phpobject = json_decode($data)

将其转换为PHP对象