通过form.submit方法发送请求时访问服务器响应文本?

时间:2015-03-26 15:17:42

标签: ajax extjs extjs4 form-submit

请考虑以下代码。我需要在失败/成功方法中访问“原始响应文本”。我该怎么做?

myFormPanel.getForm().submit({
    url: 'updateConsignment.php',
    success: function(form, action) {
       Ext.Msg.alert('Success', action.result.msg);
    },
    failure: function(form, action) {
        switch (action.failureType) {
            case Ext.form.action.Action.CLIENT_INVALID:
                Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                break;
            case Ext.form.action.Action.CONNECT_FAILURE:
                Ext.Msg.alert('Failure', 'Ajax communication failed');
                break;
            case Ext.form.action.Action.SERVER_INVALID:
               Ext.Msg.alert('Failure', action.result.msg);
       }
    }
});

1 个答案:

答案 0 :(得分:0)

尝试:

myFormPanel.getForm().submit({
    url: 'updateConsignment.php',
    success: function(form, action) {
       console.log(action.result);
       Ext.Msg.alert('Success', action.result.msg);
    },
    failure: function(form, action) {
        console.log(action.result);
        switch (action.failureType) {
            case Ext.form.action.Action.CLIENT_INVALID:
                Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                break;
            case Ext.form.action.Action.CONNECT_FAILURE:
                Ext.Msg.alert('Failure', 'Ajax communication failed');
                break;
            case Ext.form.action.Action.SERVER_INVALID:
               Ext.Msg.alert('Failure', action.result.msg);
       }
    }
});

action.result应包含服务器的响应。

您可以使用here

所述的action.response来获取RAW回复