PDA

View Full Version : Problem with JSON



DevKevin
26 Apr 2011, 12:23 AM
Hi,

Firstly, I'm new in developing Sencha touch.

I've a file with my model and my store :


Ext.regModel("mvcproject.models.myModel", {
fields: [
{name: 'sCode'},
{name: 'sDescription'}
],

});

mvcproject.stores.myModel = new Ext.data.Store({
autoLoad: true,
model: 'mvcproject.models.myModel',
extraParams: {
format: 'json',
},
proxy: {
type: 'scripttag',
url: 'http://footballpool.dataaccess.eu/data/info.wso/AllGroupCompetitors/JSON',
reader: {
type:'json',
root:"GroupInfo"
}
}
});


and another file containing my view :


mvcproject.views.viewOne = Ext.extend(Ext.Panel, {

dockedItems: [{
xtype: 'toolbar',
title: 'MVC Project'
},
{
xtype: 'toolbar',
title:'<h1>Accueil</h1>',
ui:'light',
cls:'sencha-toolbar'
},
{
xtype: 'tabbar',
dock : 'bottom',
ui : 'dark',
layout: {
pack: 'center'
},
items: [{
text: 'Accueil',
icon:'lib/touch/resources/icon/home-news.png',
iconMask:false,
handler: function () {
Ext.dispatch({
controller: mvcproject.controllers.myController,
action: 'goToHome'
})
},
scope:this
},
{
text: 'A propos',
icon:'lib/touch/resources/icon/home-about.png',
handler: function () {
Ext.dispatch({
controller: mvcproject.controllers.myController,
action: 'goToAbout'
})
},
scope:this

}
]
}],

items : [{
title:'grouplist',
cls:'grouplist',
xtype: 'list',
store: mvcproject.stores.myModel,
itemTpl: '{sDescription}',
fullscreen: true
}],

initComponent: function() {
console.log('View One');
mvcproject.views.viewOne.superclass.initComponent.apply(this, arguments);
}
});



In fact, I can not get data from JSON..
I've a warning in console :
"Resource interpreted as Script but transferred with MIME type application/json."

I hope you could help me.

Thank you.

DevKevin
26 Apr 2011, 3:44 AM
Nobody can help me?

Yannickdl
26 Apr 2011, 9:25 AM
Just to think along (new to Sencha myself);

What happens if you ditch the 'extraParams' part of your Store?

It seems to me that you already declare that the input data will be JSON with the reader function;




mvcproject.stores.myModel = new Ext.data.Store({
model: 'mvcproject.models.myModel',
proxy: {
type: 'scripttag',
url: 'http://footballpool.dataaccess.eu/data/info.wso/AllGroupCompetitors/JSON',
reader: {
type:'json',
root:"GroupInfo"
}
},
autoLoad: true
});



You are using Scripttag because the JSON script is on another domain than your application? // As an example below some code I use to load in some JSON into a story (I'm using AJAX though);



var schouwLijstStore = new Ext.data.Store({
model: "schouwLijst",
proxy: {
type: 'ajax',
//url: 'test.json',
url: 'php/json.php?t=lijst',
reader: {
type: 'json',
root: 'lijst'
}
},
autoLoad: true

});

mobile207
26 Apr 2011, 9:54 AM
Have you set the proper headers in your php file?

Try:

header('Content-type: application/json');

DevKevin
2 May 2011, 4:35 AM
Mobile207 :
This is not my own PHP file. I just want to test the json recovery for personal application.

Yannick :
ExtraParams not used much for this example, but I tried everything.

I tried everything but nothing works.
I don't understand.

DevKevin
2 May 2011, 4:49 AM
I just realized that the proxy ScriptTag use JSON-P but not JSON. My problem is he coming here?

realjax
2 May 2011, 4:49 AM
You are using the scripttag proxy. This expects the 'other' end to wrap the result in a callback function. And I don't think that this is happening. In other words, you need a different url, one that retuns a JSONP result, otherwise you are up the smelly creek..