繁体   English   中英

未捕获的TypeError:无法读取未定义的属性'responseText'

[英]Uncaught TypeError: Cannot read property 'responseText' of undefined

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;
}

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

您应该在operationrequest对象中的异步回调中获取它,除非发生某种服务器异常或将success设置为false ,这就是为什么不在失败处理程序中获取它的原因。

为了真正了解它的功能,我建议您看一下Connection.js

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

第二种方法是这样的

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

    onSuccess: function(response) {
        var form = this.form,
            success = true,
            result = response;
            response.responseText = '{"success": true}';
            form.afterAction(this, success);
        }
    });

将此片段放在您的应用程序中,然后看一下魔术。 干杯。 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM