0
buttons: [
    {
        text: "Add User",
        id: "new-record-add-button",
        handler: function() {
            var form = this.up('form').getForm();
            form.submit({
                url: BasePath+'/main/admin/adduser',
                method: 'POST',
                waitTitle: 'Authenticating',
                waitMsg: 'Please Wait',
                success: function(form, action) {
                win.close()
                     Ext.Msg.show({
                         title:'Success'
                        ,msg:'User added successfully'
                        ,modal:true
                        ,icon:Ext.Msg.INFO
                        ,buttons:Ext.Msg.OK
                });
                },

            failure: function(form, action) {

                console.log(action.response.responseText);
                obj = Ext.JSON.decode(action.response.responseText);
                console.log(obj);
                Ext.Msg.alert('Error',obj.errors)
                form.reset();
            }
        })

                //this.up("window").close();
        }

    },
    {
        text: "Cancel",
        handler: function() {
            this.up("window").close();
        }
    }
]

当我到达表单中的故障功能时,我收到以下错误:

Uncaught TypeError: Cannot read property 'responseText' of undefined 

这是我的 php 代码:

public function adduserAction()
{
            $response = new JsonModel();
            //$error = array();
            $errors="";
            if(!ctype_alpha($_POST["first_name"])) {
                $errors.="First Name cannot contain characters and numbers";
            }
            if(!ctype_alpha($_POST["last_name"])) {
                $errors.="Last Name cannot contain characters and numbers";
            }

            if(!filter_var($_POST['email_address'], FILTER_VALIDATE_EMAIL)) {
                $errors.="Email should be of the format john.doe@example.com";
            }
            if(empty($_POST["role"])) {
                $errors.="Role cannot be empty";
            }
            if($errors!="") {
                $response->setVariables(array("success"=>false, "errors"=>$errors));

            }
            else {
                $response->setVariables(array("success"=>true, "errors"=>$errors));

            }
            return $response;
}
4

2 回答 2

0

responseTextecho是一个 ExtJs 的东西 - 它表示在被解码之前从服务器返回的实际文本(例如,使用)。

您应该在operationorrequest对象中的异步回调中获取它,除非存在某种服务器异常或者如果您设置successfalse,这就是您没有在失败处理程序中获取它的原因。

要真正了解它发生了什么,我建议您查看Connection.js

于 2012-11-28T22:31:26.800 回答
0

如果您通过 ExtJs 提交表单,那么在表单提交成功时,需要将 response.responseText 设置为 {"sucess":"true"}。如果您将表单提交到某个页面,则必须确保您将从后端返回此对象。否则,您必须覆盖现有的 onSuccess 方法。

第二种方式是这样的,

Ext.override(Ext.form.action.Submit,{

    onSuccess:函数(响应){
        var form = this.form,
            成功=真,
            结果=响应;
            response.responseText = '{"成功": true}';
            form.afterAction(this, success);
        }
    });

将此代码段放在您的应用程序中,看看它的神奇之处。干杯。:)

于 2013-06-05T09:41:29.417 回答