View Full Version : How to get server response after call model.save()

27 Jun 2013, 4:39 AM
I want to let user know why the request is failed after calling model.save().
So I let server responses {"success":true,"msg": "XXX"}.
But it seems that failure function is not able to get response.

scope: this,
success: function(record, operation) {
console.log(operation.response); // I can get server response in success

failure: function(record, operation) {
console.log(operation.response); // undefined

I have seen someone listen on a exception event in proxy to get the response,
but it's not very graceful. Why does the failure can't get response?

1 Jul 2013, 12:23 PM
You can use a callback config in save() like below:

Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: ['name'],
proxy: {
type: 'ajax',
url: 'data/json.json',
reader: 'json'

var model = Ext.create('MyModel');

callback: function (records, operation, success) {
if (!success) {

Example response:

"success": false,
"msg": "server response"

Or if you want to handle every server response globally you can do something like:

Ext.Ajax.on('requestcomplete', function (conn, response, options) {
var resp = Ext.decode(response.responseText);
if (resp.success === true) {
cosnole.log('success = true');
} else {