存储更新API响应成功和失败

时间:2013-12-09 06:02:59

标签: php json extjs

var UserStore = Ext.create('Ext.data.JsonStore', {
    model: 'VehicleModel',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: 'get-vehicle.php',
        api: {
                create: 'insert-vehicle.php',
                //read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
                update: 'update-vehicle.php',
                //destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
                   success: function(action){
                           Ext.MessageBox.show({
                           title: 'Information',
                           msg: action.result.message,
                           buttons: Ext.Msg.OK,
                           icon: Ext.MessageBox.INFO
                         });
                   },
                   failure: function(action){
                            Ext.MessageBox.show({
                           title: 'Error',
                           msg: action.result.message,
                           buttons: Ext.Msg.OK,
                           icon: Ext.MessageBox.ERROR
                         });
                   }
            },

        reader: {
            type: 'json',
            idProperty: '_id'
        },
        writer: {
            type: 'json',
            id: '_id'

         }
    }
});

这是php update success return

<?php
$data = file_get_contents("php://input");
//echo $data;
//$obj = var_dump(json_decode($data));

$obj = json_decode($data);
$_id = $obj->{'_id'};
$Plat_No = $obj->{'Plat_No'};

mysql_connect("localhost", "root", "Apacheah64") or die("Could not connect");
mysql_select_db("db_shuttlebus") or die("Could not select database");

$query = "UPDATE tbl_vehicle SET Plat_No ='". $Plat_No ."' WHERE _id=".$_id;

if (mysql_query($query)){
    echo '{"success":true,"message":"Update Success !"}';
}else{
    echo '{"success":false,"message":"Update Failed !"}';
}

?>
这是fireBug已经显示成功,但为什么仍然无法弹出消息框? enter image description here

1 个答案:

答案 0 :(得分:2)

您需要在config对象中定义successfailure个处理程序,并将其作为参数传递给store.sync()方法。 Doucmentation:http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-sync

UserStore.sync({
   success: function() { 
      // success sync state handler code
   },
   failure: function() { 
      // failure sync state handler code
   }
})