title: Success and Failure functions in a store - Ext JS
body: <p>I have a request which, on success, loops through each attribute of a JSON response and adds it to my <code>store</code>:</p>
  
  <pre><code>var request = Ext.Ajax.request({
      url: 'MCApp',
      jsonData: searchquery,
      params: {
          start: 0,
          limit: itemsPerPage
      },
      success: function(response) {
          mainresponse = response.responseText;
          if (mainresponse.length == 0) {
              alert('No results returned');
              return;
          }
          var decoded = Ext.decode(mainresponse);
          for (var i = 0; i &lt; decoded.elements.length; i++) { // loop over decoded data
              var element = decoded.elements[i].element;
              var model = {};
              for (var x = 0; x &lt; element.attributes.length; x++) { // loop over attributes
                  var attribute = element.attributes[x];
                  model[attribute.attrname] = attribute.attrvalue; // mapping element names &amp; attributes
              }
              newstore.add(model); // implicitly cast data as Model
              models[i] = model;
          }
          newstore.loadRawData(models);
      },
      failure: function() {
          alert('Search Failed: Could not reach the server')
      }
  });
  </code></pre>
  
  <p>I have now recreated the <code>request</code>above within my <code>store</code>. What I need to do is add these same success and failure functions.</p>
  
  <pre><code>var store = Ext.create('Ext.data.Store', {
      storeId: 'resultsetstore',
      autoLoad: false,
      pageSize: itemsPerPage,
      fields: [
          { name: 'id',          type: 'auto' },
          { name: 'name',        type: 'auto' },
          { name: 'description', type: 'auto' }
      ],
      proxy: {
          type: 'ajaxwithpayload', //customized proxy to read "jsonData" 
          url: 'MCApp',
          jsonData: searchquery,
          reader: {
              type: 'json',
              root: 'elements'
          }
          success: { /* success functions */ },
          failure: { /* failure functions */ }
      }
  
  });
  </code></pre>
  
  <p>Here's what my response looks like:</p>
  
  <pre><code>{
     "elements":[
        {
           "element":{
              "name":"Element Name", 
              "id":"Element ID",
              "attributes":[
                 {
                    "attrname":"id",
                    "attrvalue":"This is the ID"
                 },
                 {
                    "attrname":"name",
                    "attrvalue":"This is the name"
                 },
                 //etc.
  </code></pre>
  
  <p>1) Is there any way to recreate these functions on my store?</p>
  
  <p>2) Is decoding my response this way the best way to load my response into my store?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I'm using the callback function when I load the store: </p>
  
  <pre><code>store.load({
      params: { start: 0, limit: itemsPerPage },
      callback: function(options, success, response, records) {
          if (success) {
              alert(response.responseText);
          }           
      }
  });
  </code></pre>
  
  <p>However, I'm getting an <code>undefined</code> in my alert, and it's telling me there are 0 records loaded. But when I look at my response in Firebug I see my JSON string returned just fine.</p>