PDA

View Full Version : Weird success / failure behaviour



bkraut
9 Sep 2009, 11:38 AM
Hi,

I'm using java as a server side. On my form, I have a button for deleting an object in a grid with following code:



Ext.Ajax.request({
url: 'Controller/Reporter/reportcategory.Delete',
timeout: 10000,
waitMsg:'Deleting report category',
params: {
id: node.attributes.attributes[0].record.id
},
success: function(response,recordData ) {
node.getOwnerTree().reloadTreeNode(node);
console.log(Ext.decode(response.responseText).success);
console.log(recordData);
Ext.MessageBox.alert ('Message', 'Record successfully removed.');
}.createDelegate(this),
failure : function(response) {
Ext.MessageBox.alert ('Error', 'Record can not be removed.');
},
scope: this
});


If this object has references in the database the deletion is not allowed, so I create an error on the server side, which produces following json:



{"message":"could not delete: [objectverse.mdx.reporter.ReportCategory#7]","success":false}


Anyway, on the client side, I get a success event, not a failure. Where should I search for a solution?

Thanks in advance.

jnicora
9 Sep 2009, 11:54 AM
The failure method is called when the server sends back a failure code. If you catch the error and pass back a 200 code (success) then the success method id called.

bkraut
9 Sep 2009, 12:57 PM
How can I tell a server to send back failure code?
Is this 501 message?