PDA

View Full Version : Unable to retrieve data from script tag proxy



sachin sachdeva
29 Apr 2011, 7:37 AM
Hi... I am using script tag proxy for domain other then my application i have used it exactly in the same way as used in example..my code is..



Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady : function() {

Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});

var groupingBase = {
itemTpl: '<div class="contact2"><strong>{firstName}</strong> {lastName}</div>',
selModel: {
mode: 'SINGLE',
allowDeselect: true
},
grouped: true,
indexBar: false,

onItemDisclosure: {
scope: 'test',
handler: function(record, btn, index) {
alert('Disclose more info for ' + record.get('firstName'));
}
},

store: new Ext.data.Store({
model: 'Contact',

proxy : {
type : 'scripttag',
url : 'http://wwwdev.XXX.com/ebook/app_admin_ebooks.json',
reader : {
type : 'json'

}
},
autoLoad : true

})
};

debugger;
if (!Ext.is.Phone) {
new Ext.List(Ext.apply(groupingBase, {
floating: true,
width: 350,
height: 370,
centered: true,
modal: true,
hideOnMaskTap: false
})).show();
}
else {
new Ext.List(Ext.apply(groupingBase, {
fullscreen: true
}));
}
}
});







My json is
data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Ed', lastName: 'Spencer'}




]


Plz let me know where i am mistaken ..i am new to sencha touch.

julsjil
10 Oct 2011, 3:14 AM
:-/can anyone help me to solve it out. i have been cracking my head since 2 weeks.

Designworxz
10 Oct 2011, 6:35 PM
Same here not able to read JSON data.



Ext.regModel('Test', { fields: [ {name: 'Branch', type: 'string'}, {name: 'City', type: 'string'} ], proxy:{ type: 'scripttag', url: 'JSONP REST based Service', reader: 'json', method:'GET', autoLoad: false, afterRequest: function (request, success) { if (success) { alert('Successfully loaded '); alert(request.data); console.log('Successfully loaded '); } else { alert('Failed to load '); console.warn('Failed to load '); } console.info(request); } }});


Store = new Ext.data.Store({ model: 'Test' });



Store.load();

Store.getCount(); //gives 0

But in fiddler i can see data coming
stcCallback1001([{"Branch":"abc","City":"123"}]);

parth.suthar
11 Oct 2011, 12:47 AM
Hi,
In scripttag proxy you need to create 1 callback function. Refer below example,that might can help your problem.


Here, I have created 1 model and store,use scripttag proxy.

Code ::


Ext.regModel('User', {
fields: ['id', 'name', 'email']
});


var store = new Ext.data.Store({
model: 'User',
proxy: {
type: 'scripttag',
url : 'scripttagproxycheck.js'
}
});


store.load();

While in my scriptagproxycheck.js, i have called callback function passing the data which i want from server.

code ::

scripttagproxycheck({name:'parth',dsf:'sdfs'});

And with your model and store code,additionally you have to create callback function same as called in above code.

callback function code::


function scripttagproxycheck(data)
{
alert(data);
}