1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    13
    Vote Rating
    0
    rans is on a distinguished road

      0  

    Default Unanswered: get store data with node.js

    Unanswered: get store data with node.js


    Hello,
    I am trying to get my store data trough node.js
    This is the part from my program that returns the data from the node.js
    Code:
      collection.find().toArray(function(err, items) {
        
                var leaders = 
                   {
                           leader: items,
                   };
     
                res.send(leaders);
    And it’s return the data like this:
    Code:
    {
      "leader": [
        {
          "name": "name 1",
          "points": "210",
          "_id": "51069337e3120bcc29000001"
        },
        {
          "name": "name 2",
          "points": "156",
          "_id": "51069337e3120bcc29000002"
        }
      ]
    }
    My model is:
    Code:
    Ext.define('FB.model.leaderboardModel', { 
            extend: 'Ext.data.Model',
            fields: ['name', 'points', '_id'],
    });
    My store is:

    Code:
    Ext.define('FB.store.leaderboardStore', { 
            extend:'Ext.data.Store',
            model:'FB.model.leaderboardModel',
            autoLoad: true,
            sorters: {
                   property:'ID',
                   direction:'ASC'
            },
            proxy:{ 
                   type: 'jsonp',
                   url: 'http://localhost:3000/InnoUsers',
                   reader: {
                           type: 'json',
                           root: 'leader'
            }
     
                  
            },
           
    });
    I get the error:
    “Uncaught SyntaxError: Unexpected token :”

    Moreover when I debug I can see that the data come perfectly like this:
    Code:
    {
      "leader": [
        {
          "name": "name 1",
          "points": "210",
          "_id": "51069337e3120bcc29000001"
        },
        {
          "name": "name 2",
          "points": "156",
          "_id": "51069337e3120bcc29000002"
        }
      ]
    }
    And the error is on "leader":

    I can’t understand why I get this error
    any ideas?
    Help please

  2. #2
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    Is the content type on the response being set to 'application/json'?

    I also note that you're using a 'jsonp' Proxy, but it doesn't appear that you're doing a cross-domain call. Maybe try an 'ajax' proxy instead?
    Last edited by friend; 28 Jan 2013 at 9:59 AM. Reason: further comments

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    13
    Vote Rating
    0
    rans is on a distinguished road

      0  

    Default


    the content type is json
    Content-Type:
    application/json; charset=utf-8

    and yes, i am using cross-domain
    do you have another idea?

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    13
    Vote Rating
    0
    rans is on a distinguished road

      0  

    Default


    Hi all,

    I found my error.
    the mistake was on the node.js server
    I change on the response to:
    Code:
    res.setHeader('Content-Type', 'text/javascript;charset=UTF-8');
                 res.send(req.query["callback"] + '({"records":' +  JSON.stringify(items) + '});');

Thread Participants: 1

Tags for this Thread