1. #1
    Sencha User SunboX's Avatar
    Join Date
    Mar 2010
    Posts
    238
    Answers
    5
    Vote Rating
    28
    SunboX has a spectacular aura about SunboX has a spectacular aura about

      0  

    Question Answered: How to tell Ext.data.reader.Reader to use state code 200 as successProperty?

    Answered: How to tell Ext.data.reader.Reader to use state code 200 as successProperty?


    Hi, I want to fetch data with JsonP from an foreign Server-API. It returns for success:
    Code:
    {"state":200,"results":[...]}
    and in case of an failure, something like this:
    Code:
    {"state":402,"message":"Please provide a valid ..."}
    Now Ext.data.reader.Reader expects an boolean for successProperty. How will I tell the reader, that all worked fine, if state = 200?

    I think of something like this:
    Code:
    Ext.define('App.model.CoolModel', {    extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'string'},
        ],
        proxy: {
            type: 'jsonp',
            url: 'http://xyz/search/coolapi.json',
            reader: {
                type: 'json',
    
                success: function(data) {
                    return data.state == 200;
                },
    
                root: 'results'
            }
        }
    });
    could someone please point me the right direction? thx Sunny

  2. You will have to override the proxy in the processResponse method. There is a check where result.success !== false, that's where it checks to see if the success property is true/false. So after the result variable get's filled with data from the reader, you will need to set result.success.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,206
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The successProperty is expecting a boolean value... 200 is truthy in javascript but so is 500 or 402
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User SunboX's Avatar
    Join Date
    Mar 2010
    Posts
    238
    Answers
    5
    Vote Rating
    28
    SunboX has a spectacular aura about SunboX has a spectacular aura about

      0  

    Default


    Yes, makes sense. But how do I tell the reader that response state = 200 is success?

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,206
    Answers
    3517
    Vote Rating
    856
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You will have to override the proxy in the processResponse method. There is a check where result.success !== false, that's where it checks to see if the success property is true/false. So after the result variable get's filled with data from the reader, you will need to set result.success.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Sencha User SunboX's Avatar
    Join Date
    Mar 2010
    Posts
    238
    Answers
    5
    Vote Rating
    28
    SunboX has a spectacular aura about SunboX has a spectacular aura about

      0  

    Thumbs up


    Ah, ok great. Thanks!

Thread Participants: 1