Results 1 to 6 of 6

Thread: Store reader handling empty response

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User tf.alves's Avatar
    Join Date
    Feb 2010
    Location
    Portugal
    Posts
    54
    Answers
    3

    Default Answered: Store reader handling empty response

    Hello everyone,

    My server not always returns a JSON string, sometimes it returns nothing (depending on the amount of items it has at the moment). The problem comes when I have to handle the response... It throws an exception:
    Uncaught TypeError: Cannot read property 'length' of undefined
    How can I handle this empty responses, in order to just show the emptyMessage instead of throwing the exception?

    The store code is as follows:

    Code:
    App.stores.events_store = new Ext.data.Store({    model: 'EventItem',
        sorters: 'data',
        proxy: {
            type: 'ajax',
            url: 'calendar.php',
            reader: {
                type: 'tree',
                root: 'items'
            }
        }    
    });

    Edit: Ok, I know if I return an empty JSON like {"items":{}} it will work, but how about if the response is nothing ("")?

  2. Quote Originally Posted by tf.alves View Post
    Edit: Ok, I know if I return an empty JSON like {"items":{}} it will work, but how about if the response is nothing ("")?
    IMO, that is not a good idea for app development. At least change the status code to tell the Proxy that something went wrong but you should at least return something.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •