View Full Version : AJAX not properly handling errors???

1 Feb 2010, 7:49 AM
I have this code in the PHP script which is being invoked:

$result['success'] = false;
$result['errors']['reason'] = 'You do not have proper permissions to create manufacturers';

header('Content-Type: application/x-json');
echo json_encode($result);

There are no conditionals or anything this code is all that exists.

Here is the extJS code:

url: 'services/index.php/system/manufacturer/create',

params: {name: val},

success: function(){
alert('SUCCESS creating manufacturrer');


failure: function(form, action){

if(action.failureType == 'server'){

obj = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.alert('Operation Failed!', obj.errors.reason);

The failure never executes only the success handler seems to be invoked, despite ensuring the PHP script is returning an error JSON structure in hopes of triggering the failure handler.

What am I missing?

The URI is correct Firebug is showing the expected results...