Extjs4.1, Get response message after repository synchronization

How to get a response message in the failure function?

store.sync({
 success : function(){},
 failure : function(response, options){
   console.log(response.responseText); //it does not work, because there is responseText attr in response
 }  
});

The text of the answer is

{"success":false,"message":"Test Error"}

Does anyone know please advise me.

thank

[EDIT]

console.log(response); 

then

enter image description here

+5
source share
3 answers

I’m not sure if you ever understood this, but the suggestions above, I’m sure, are wrong. You need to look at the store proxy request exception.

Below is the code to call before synchronizing the repository.

Ext.Ajax.on('requestexception', function (conn, response, options) {

  if (response.status != 200) {
    var errorData = Ext.JSON.decode(response.responseText);
    Ext.Msg.alert('Creating User Failed',errorData.message);
  }

});

Sorry to stick out this old post, but it just pains me to see the answers above, as I just went through the same fight.

NTN x.

+6
source

Here is what you need:

store.sync({
    success: function(batch) {
        Ext.Msg.alert('Success!', 'Changes saved successfully.');
    },
    failure: function(batch) {
        Ext.Msg.alert("Failed", batch.operations[0].request.scope.reader.jsonData["message"]);
    }
});
+2
source

.

  • Ext.Ajax.on , . , . Ext.Ajax.on - , . . .
  • batch.operations [0] .response.responseText can also be used, but this is an unreliable way to get a response, since the response object will not always be filled (depends on the request and whether there are exceptions, 404, 500, success: false, etc.)

Exposition

    // This picked up my autocomplete comboboxes load - not what I wanted!
    Ext.Ajax.on({
        requestcomplete: {
            fn: callback,
            scope: this,
            single: true
        },
        requestexecption: {
            fn: callback,
            scope: this,
            single: true
        }
    });

Current solution

It still doesn't have the answer I'm looking for, but meh.

    store.sync({
        failure: function (batch, eOpts) {
            // 'this' is the Ext.data.proxy.Ajax object
            // or whatever proxy you are using
            var data = this.getReader().jsonData,
                raw_data = this.getReader().rawData;
        }
    });

I'm not sure how this handles my full stack of exceptions, but I will correct my post based on the server-side exceptions that I found (404, 500, etc.).

+2
source

All Articles