简体   繁体   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();
        }
    }
]

I am getting the following error when I reach the failure function in my form: 当我以表单到达故障功能时,出现以下错误:

Uncaught TypeError: Cannot read property 'responseText' of undefined 

This is my php code: 这是我的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 is an ExtJs thing - it represents the actual text returned from the server (eg, using echo ) before being decoded. responseText是ExtJs的东西-它表示在解码之前从服务器返回的实际文本(例如,使用echo )。

You should get it in asynchronous callbacks within the operation or request objects, unless there was a server exception of a sort or if you set success to false , that's why you don't get it in the failure handler. 您应该在operationrequest对象中的异步回调中获取它,除非发生某种服务器异常或将success设置为false ,这就是为什么不在失败处理程序中获取它的原因。

To really understand what's going on with it I recommend you have a look at Connection.js . 为了真正了解它的功能,我建议您看一下Connection.js

if you do a form submit through ExtJs, then on success of the form submission it needs response.responseText to be set as {"sucess":"true"}. 如果您通过ExtJs提交表单,则在表单提交成功后,需要将response.responseText设置为{“ sucess”:“ true”}。 if you are submitting the form to some page you have to make sure that you will be returning this object from backend. 如果要将表单提交到某个页面,则必须确保要从后端返回此对象。 Or else you have to override the existing onSuccess method. 否则,您必须重写现有的onSuccess方法。

The second way is something like this, 第二种方法是这样的

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

Place this snippet in your application and see the magic. 将此片段放在您的应用程序中,然后看一下魔术。 Cheers. 干杯。 :) :)

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

相关问题 未捕获的TypeError:无法读取未定义的属性'getProxy' - Uncaught TypeError: Cannot read property 'getProxy' of undefined 未捕获的类型错误:无法读取未定义的属性“isSynchronized” - Uncaught TypeError: Cannot read property 'isSynchronized' of undefined 未捕获的TypeError:无法读取未定义的属性“位置” - Uncaught TypeError: Cannot read property 'location' of undefined 未捕获的类型错误:无法读取未定义的属性“销毁” - Uncaught TypeError: Cannot read property 'destroy' of undefined 未捕获的类型错误:无法读取未定义的属性“dom” - Uncaught TypeError: Cannot read property 'dom' of undefined 未捕获的类型错误:无法使用 Sencha 读取未定义的属性“应用” - Uncaught TypeError: Cannot read property 'apply' of undefined with Sencha ExtJS:未捕获的TypeError:无法读取未定义的属性“作用域” - ExtJS: Uncaught TypeError: Cannot read property 'scope' of undefined Extjs5 treepanel [未捕获的TypeError:无法读取未定义的属性'create'] - Extjs5 treepanel [Uncaught TypeError: Cannot read property 'create' of undefined] ExtJs错误:未捕获TypeError:无法读取未定义的属性'removeCls' - ExtJs Error: Uncaught TypeError: Cannot read property 'removeCls' of undefined d3.js - 未捕获的TypeError:无法读取未定义的属性“数据” - d3.js - Uncaught TypeError: Cannot read property 'data' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM