当前位置: 代码迷 >> JavaScript >> Ext Ext.Decode = Ext.util.JSON.Decode 步骤介绍
  详细解决方案

Ext Ext.Decode = Ext.util.JSON.Decode 步骤介绍

热度:744   发布时间:2012-08-16 12:02:16.0
Ext Ext.Decode = Ext.util.JSON.Decode 方法介绍
在使用Ext 执行数据操作的时候 ,有时候我们需要和后台服务器交换数据,

        如果是做表单数据提交的时候由于要提交大量数据,我们通常的方法是:

{
                    name: "save",
                    id: "save",
                    text: "保存",
                    tooltip: "保存公司信息",
                    disabled: true
                    , handler: function() {
                        var baseForm = companyFormPaenl.getForm();


                        if (baseForm.isValid()) {
                            //弹出效果
                            Ext.MessageBox.show({
                                msg: '正在保存,请稍等...',
                                progressText: 'Saving...',
                                width: 300,
                                wait: true,
                                waitConfig: { interval: 200 }


                            });


                            baseForm.submit({
                                url: "URL/CompanyInfo/SaveCompanyInfo.aspx",
                                method: "POST",
                                success: function(form, action) {
                                    var flag = action.result.success;
                                    if (flag == true) {
                                        Ext.MessageBox.alert("恭喜", "公司保存成功!");
                                    }


                                },
                                failure: function(form, action) {


                                    Ext.MessageBox.alert("提示!", "公司保存失败!");


                                }


                            });
                        }


                    }
                }


这样将会使用 POST  方式把我们的数据全部提交给后台服务器,

但是有时候我们只是做删除操作只需要传递简单的几个数据过去,所以不需要大费周折使用上面的方法执行操作,这样我们可以使用Ext 另外一个方法:

   name: "delete",
                    id: "delete",
                    text: "删除",
                    tooltip: "删除公司信息",
                    disabled: true
                    , handler: function() {


                        Ext.Ajax.request({
                            url: "URL/CompanyInfo/DeleteCompanyInfo.aspx",
                            method: "POST",
                            params: { id: Ext.get("hidCompanyId").dom.value },
                            success: function(response, options) {                               
                                var jsonObj = Ext.decode(response.responseText);


                                Ext.Msg.alert("提示", "删除成功");
                            },
                            failure: function(response, options) {
                                Ext.Msg.alert("提示", "删除失败");
                            }


                        });


                    }
                }





             这个方法的返回值用response.responseText 得到,但是大家注意,response.responseText 返回的是一个字符串,如果要把他转换成对象,使用

  Ext.Decode() , 他讲字符串转换成一个 json 对象,注意:response.responseText  格式要有严格要求,

    这里提供两个response.responseText  例子: "{ 'success':true, 'msg':'恭喜你,操作成功!', 'action':'1' }";

           var jsonObj = Ext.decode(response.responseText);

      这样将会产生一个 Json 对象了

  相关解决方案