Reputation: 10624
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,
Upvotes: 5
Views: 8371
Reputation: 1228
The long and short of it all of these answers are incorrect or inefficient.
Exhibit a
// 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
This still does not have the response I am 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 am not sure how this handles my full exception stack of cases, but I will amend my post based on the server-side exceptions I discover (404, 500, etc.)
Upvotes: 2
Reputation: 15478
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.
Upvotes: 6
Reputation: 3694
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"]);
}
});
Upvotes: 2