Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs4.1, Retrieve response message after store sync

Tags:

extjs4.1

How to retrieve response message in 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
 }  
});

Response Text is like this,

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

Anybody know, please advice me.

Thanks

[EDIT]

console.log(response); 

then,

enter image description here

like image 257
Expert wanna be Avatar asked Aug 09 '12 13:08

Expert wanna be


2 Answers

I'm not sure if you ever figured this out, but the suggestions above I'm pretty sure are wrong. You need to look at the request exception of the store proxy.

Here is some code to call before you do the store sync.

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 for digging this old post up but it just hurt to see the answers above since I just went through the same struggle.

HTH's.

like image 146
Peter Kellner Avatar answered Sep 21 '22 20:09

Peter Kellner


Here's 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"]);
    }
});
like image 42
Slayer Birden Avatar answered Sep 21 '22 20:09

Slayer Birden