PDA

View Full Version : crossdomain ajax request



Mycoding
12 Mar 2011, 5:11 AM
Please give a hint.
How to do cross-domain ajax request I am trying but I can't to understand how to do it.

I look through the aticle of Animal but article was dedicated to ExtJS 2.x
I need it for ExtJS 3.3.1

And I want to ask about Ext.data.ScriptTagProxy.
Is the way to use it for ajax request cross-domain?

Mycoding
12 Mar 2011, 6:02 AM
At tte moment I am trying to use cross domain in grid.

Code is here.
But I don't know why information is not show, although it is loaded and is really good.
Json is here http://vreshenie.ru/work/comet/json-test/grid.json


function renderUniversal(value, p, record){
console.log(value);
return String.format("<span class='cute'>{0}</span>",value);
}

var remoteJsonStore = new Ext.data.JsonStore({
root: 'rows',
idProperty: 'id',
autoLoad:true,
fields: ['id', 'login', 'msg'],
proxy : new Ext.data.ScriptTagProxy({
url : 'http://vreshenie.ru/work/comet/json-test/grid.json'
})
});

new Ext.Window({
title:'Cross domain',
width:300,
height:150,
layout:'fit',
items:[{
xtype:'grid',
store: remoteJsonStore,
stripeRows:true,
loadMask: true,
columns:[{
id: 'id',
header: 'ID',
dataIndex: 'id',
width: 50,
hidden:true,
renderer:renderUniversal
},{
header: '?????',
dataIndex: 'login',
width: 50,
renderer:renderUniversal
},{
header: '?????????',
dataIndex: 'msg',
width: 150,
renderer:renderUniversal
}]
}]
}).show();

mitchellsimoens
12 Mar 2011, 1:02 PM
JSON is not correct.

JSON error:


Error: Parse error on line 1:
{success:true,rows:[{
-^
Expecting 'STRING', '}'

jratcliff
12 Mar 2011, 3:09 PM
You need to wrap your json in a callback function. Take a look at the forum search example and use firebug to look at the data that comes back.

http://dev.sencha.com/deploy/dev/examples/form/forum-search.html

Notice that it wraps the json in a function called stcCallback1001.

More info is in the docs on this: http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.ScriptTagProxy

And here is an example of using ScriptTagProxy to show the tweets of Sencha Inc.




Ext.onReady(function() {

var remoteJsonStore = new Ext.data.JsonStore({
idProperty: 'id',
autoLoad:true,
fields: ['created_at', 'retweet_count', 'text'],
proxy : new Ext.data.ScriptTagProxy({
url : 'http://twitter.com/statuses/user_timeline/senchainc.json'
})
});

new Ext.Window({
title:'Sencha Inc Tweets',
width:500,
height:250,
layout:'fit',
items:[{
xtype:'grid',
store: remoteJsonStore,
stripeRows:true,
loadMask: true,
autoExpandColumn : 'tweet',
columns:[{
header: 'Created',
dataIndex: 'created_at',
width: 180
},{
header: 'RTs',
dataIndex: 'retweet_count',
width: 30
},{
header: 'Tweet',
dataIndex: 'text',
id: 'tweet'
}]
}]
}).show();
});