1

我能够在 firebug 中看到 json 响应,但是当我成功解码表单的 ACTION 时,它给出了 undefined 。

{
    xtype: 'form',
    x: 30,
    y: 520,
    height: 80,
    bodyPadding: 10,
    title: 'myuploadform',
    fileUpload: true,
    standardSubmit: false,
    autoHeight: true,
    bodyStyle: 'padding: 10px 10px 10px 10px;',
    labelWidth: 50,

    items:[{
        xtype: 'fileuploadfield',
        id: 'filedata',
        emptyText: 'Select a document to upload...',
        fieldLabel: 'File',
        buttonText: 'Browse'
    }],

    buttons: [{
        text: 'Upload',
        handler: function() {
            var form = this.up('form').getForm();
            if(form.isValid()){
                alert("submit");

                form.submit({
                    url: 'myurl'
                    waitMsg: 'Uploading file...',

                    success: function (form,action) {
                        var data= Ext.JSON.decode(action.response.responseText);
                        alert("Success: " + data.msg);
                        Ext.Msg.alert('Success', action.result.message);
                    },

                    failure: function (form, action) {
                        var data = Ext.decode(action.response.responseText);
                        alert("Failure: " + data.msg);
                    }
                });
            }
        }
    }]
}

我的 url 返回 json 响应,我想在提交成功时处理它。如果有人尝试过,请告诉我

4

2 回答 2

4

尝试纯 JavaScript 方式

var data= JSON.parse(action.response.responseText);

或 ExtJs 3.x 方式

var data= Ext.util.JSON.decode(action.response.responseText);

对于 ExtJs 4 及更高版本

var data= Ext.JSON.decode(action.response.responseText);
于 2013-10-07T11:23:15.337 回答
1
         success : function(response, opts)
            {
                response = Ext.decode(response.responseText);
                if(response.success==true){
                    alert("Authentication sucess");

                }else{

                    Ext.MessageBox.alert('Alert','Invalid User name or password');
                }


            },
    failure:function(response, opts)
              {
                  Ext.MessageBox.alert('Alert','Exception is occured please contact administrator');


              }
于 2013-10-08T06:24:49.737 回答