PDA

View Full Version : get store data with node.js



rans
28 Jan 2013, 7:33 AM
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

collection.find().toArray(function(err, items) {

var leaders =
{
leader: items,
};

res.send(leaders);

And it’s return the data like this:

{
"leader": [
{
"name": "name 1",
"points": "210",
"_id": "51069337e3120bcc29000001"
},
{
"name": "name 2",
"points": "156",
"_id": "51069337e3120bcc29000002"
}
]
}

My model is:

Ext.define('FB.model.leaderboardModel', {
extend: 'Ext.data.Model',
fields: ['name', 'points', '_id'],
});

My store is:


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:

{
"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 :)

friend
28 Jan 2013, 9:55 AM
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?

rans
5 Feb 2013, 5:27 AM
the content type is json
Content-Type:
application/json; charset=utf-8

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

rans
6 Feb 2013, 4:47 AM
Hi all,

I found my error.
the mistake was on the node.js server
I change on the response to:

res.setHeader('Content-Type', 'text/javascript;charset=UTF-8');
res.send(req.query["callback"] + '({"records":' + JSON.stringify(items) + '});');