开发者

extjs REST api saving data

I'm saving a user to my server's database using rest services (POST). The user gets sent and saved allright in my db but the response is not interpreted right and the execution stops. Searched over and over again for a solution to my problem but can't seem to find any.

Here's my controller code:

addUser: function () {
    var form = this.addUserWindow.down('form').getForm ();
    if (form.isValid()) {
        var user = new AP.model.User(form.getValues ());
        if ( user.validate () ) {
            user.save ({
                success: function() {
                    this.add开发者_开发知识库UserWindow.destroy();//     destroys this window
                    this._reloadStore ();//     reloads a grid
                }
            });
        }
    }
}

On user.save method the execution stops even though the data is posted and record saved and returned like this:

{"data":{"username":"xyz","email":"z@x.com","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

The error says:

Uncaught TypeError: Cannot read property 'data' of undefined
callback                            ext-all-debug.js:26824
Ext.define.processResponse                  ext-all-debug.js:26044
(anonymous function)                        ext-all-debug.js:26240
Ext.apply.callback                          ext-all-debug.js:5140
Ext.define.onComplete                       ext-all-debug.js:20950
Ext.define.onStateChange                    ext-all-debug.js:20912
(anonymous function)


The return record:

{"data":"username":"xyz","email":"z@x.com","password":"abcd","id":"1"},"success":true,"error":null,"errors":[]}

where "data" should be the root property defined in the reader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜