0
votes

I have a store with a proxy configured to update my database.

proxy: { type: "ajax", api: { create: MySite.app.BaseURL + 'Member.php?action=create', read: MySite.app.BaseURL + 'Member.php', update: MySite.app.BaseURL + 'Member.php?action=update', destroy: MySite.app.BaseURL + 'Member.php?action=delete' },

This all works fine but what I would really like is to be able to read the response so to report to the user success or failure of an update.

For example when an update is successful the json below is returned in the response,

{"success":true,"message":"Updated"}

And if not successful then the following is returned,

{"success":false,"message":"something terrible happened"}

I've tried adding a listener to the store as below but this doesn't seem to pick up the response.

    listeners: {

        success: function(response) {

                console.log(response);

                var data = Ext.JSON.decode(response.responseText.trim());

                console.log(data);  

                if(data.success == 'true') {
                console.log('success'); 
                }
        }
    },

Could anyone help?

2

2 Answers

0
votes

Stores don't fire a success event. That has to be configure in each operation using the success, failure or callback functions.

For example, when you perform a sync, you could do something like this:

myStore.sync({
    success: function(batch, options) {
       console.log(response);
    }
});

Given stores work with bacths, to have to see the batch fields in order to know if it was okay or not.

0
votes

The store will fire a 'write' event when successful. The proxy will fire an 'exception' event if there is a failure. This 'exception' event should bubble up to its parent (the store) so your listeners in the store should be for 'write' and 'exception'. You can look up the parameters to these events. For the 'write' event, the parameters should be the store itself, and the operation. The operation should have all the info you need to do the logging or whatever you want.