Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Importing Data from JSON file to Store

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default Unanswered: Importing Data from JSON file to Store

    I have begun developing an app where I use Sencha Touch for the frontend design and java to query the database on the backend. However, I am having trouble integrating the two together. I tried returning the data from a java query into a .json file in json format and then loading that into my app through a store but it doesn't seem to be working. I get the error in the Chrome console as shown below.



    I have my project contained in an eclipse Java Web Project so that I could easily utilize the localhost server. I am unsure as to why the json data is not loading into the store.

    Store:
    Code:
    
    
    Code:
    Ext.define('MyApp.store.Questions', {
        extend: 'Ext.data.Store',
        
        config: {
            autoLoad: true,
            model: 'MyApp.model.Question',
            
        proxy: {
            type: 'ajax', 
            url: 'localhost:8080/ProficyAppData/WebContent/app/store/info.json',
            reader: 'json'
        },
        listeners: {
            load: function() {
                console.log(this);
            }
        },
        }
    });
    
    
    Model:
    
    Ext.define('MyApp.model.Question', {
        extend: 'Ext.data.Model',
        
        config: {
            fields: ['id', 'criteria', 'description', 'questionName', 'type']
        }
    });
    
    
    info.json:
    
    [
         {
              "id": 1,
              "criteria": "no criteria yet",
              "description": "no description yet",
              "questionName": "no question yet",
              "type": "n/a"
         },
         {
              "id": 2,
              "criteria": "no criteria yet",
              "description": "no description yet",
              "questionName": "no question yet",
              "type": "n/a"
         },
         {
              "id": 3,
              "criteria": "no criteria yet",
              "description": "no description yet",
              "questionName": "no question yet",
              "type": "n/a"
         },
         {
              "id": 4,
              "criteria": "no criteria yet",
              "description": "no description yet",
              "questionName": "no question yet",
              "type": "n/a"
         },
         {
              "id": 5,
              "criteria": "no criteria yet",
              "description": "no description yet",
              "questionName": "no question yet",
              "type": "n/a"
         },
         {
              "id": 6,
              "criteria": "no criteria yet",
              "description": "no description yet",
              "questionName": "no question yet",
              "type": "n/a"
    
    
         }
    ]

  2. #2
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Answers
    102
    Vote Rating
    87
      0  

    Default

    Moved to ST2 Q&A forums

  3. #3
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,421
    Answers
    3900
    Vote Rating
    1271
      0  

    Default

    Are you getting any errors in the console like the CORS error? (noticed the port number in the url)
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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. #4
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default

    The only error I am getting in the console is the one I showed in the picture above. Is that what you mean?

  5. #5
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,421
    Answers
    3900
    Vote Rating
    1271
      0  

    Default

    Quote Originally Posted by mferraco View Post
    The only error I am getting in the console is the one I showed in the picture above. Is that what you mean?
    The image you have there is within your gmail account and outsiders can't see it.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default

    Oh okay sorry here is the error I get in the chrome console.

    OPTIONS localhost:8080/ProficyAppData/WebContent/app/store/info.json_dc=1342618907990&page=1&start=0&limit=25 Resource failed to load

  7. #7
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,421
    Answers
    3900
    Vote Rating
    1271
      0  

    Default

    Ok, yes, that is the browser trying to see if the server allows CORS (it does via an OPTIONS request) and your server isn't handling the OPTIONS request.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  8. #8
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default

    Any idea on how to fix this? I don't have any prior knowledge on configuring a server to allow an OPTIONS request.

  9. #9
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,421
    Answers
    3900
    Vote Rating
    1271
      0  

    Default

    I'm not going to be able to support server configurations but Apache should allow it by default.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  10. #10
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
      0  

    Default

    But as far as you can see the code for the store and models looks correct?

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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