View Full Version : Ajax call cross domain
dbottillo
14 Sep 2010, 12:24 AM
Hi,
i have to make a ajax call request cross domain
inside same domain i use:
Ext.Ajax.request({
url: 'url_same_domain.json',
success: function (response, opts){
...
},
failure: function (response, opts){
...
}
});
but how can i do this request cross domain?
i try Ext.ScriptTagProxy.request and Ext.ScriptTag.request
but it doesn't work
inside forum i found only example about store, instead i need to make this call outside a store component
Thank You
Daniele
evant
14 Sep 2010, 12:40 AM
http://dev.sencha.com/deploy/touch/docs/?class=Ext.util.JSONP
dbottillo
14 Sep 2010, 2:20 AM
ok thank you
i have another question
if my json is like:
Ext.util.JSONP.callback(
{
results: [
{
element: {
field1: ""
field2: ""
...
}
}
,{
element: {
field1: ""
field2: ""
...
}
]})
how can i make an appropriate model for binding to this json?
evant
14 Sep 2010, 2:23 AM
The same as you normally would. Just use the scripttag proxy.
dbottillo
14 Sep 2010, 2:51 AM
ok thank you
another question :D
now to load data i do:
Ext.util.JSONP.request({
url: 'url_for_data.json',
callbackKey: 'callback',
params: {
limit: 5
},
callback: function(data) {
data = data.results;
list.store.loadData(data);
}
});
and it works fine (where list in an Ext.List)
but if i want to update list with new records, how can i do?
i try
Ext.util.JSONP.request({
url: 'url_for_data.json',
callbackKey: 'callback',
params: {
limit: 30
},
callback: function(data) {
data = data.results;
list.store.add(data);
}
});
but list.store.add(data) say: 'Uncaught TypeError: Cannot read property 'id' of undefined'
i try also list.update(data) but it doesn't work...!
evant
14 Sep 2010, 2:56 AM
You totally ignored what I said above. Use a store with a scripttag proxy.
dbottillo
14 Sep 2010, 3:25 AM
ok sorry
but with scripttag proxy i have a problem that with Ext.util.JSONP.request i don't have:
store: new Ext.data.Store({
autoLoad: true,
model: 'Offer',
proxy: {
url: 'url.json',
type: 'scripttag',
reader: {
root: 'results'
}
}
}),
with this store
if my json is like:
results:[
{ id: 1, name: uno, ....., image: {
id: 90, type: jpeg
}, ...}
]
i can't get image.id! is like i can't get element nested in my json (with JSONP request i can get those element)
evant
14 Sep 2010, 3:37 AM
http://www.sencha.com/forum/showthread.php?109507-mapping
dbottillo
14 Sep 2010, 4:12 AM
ok thank you, with mapping it works
but even if with scripttagproxy i dont' understand how to update list
i try:
list.store.proxy.extraParams.limit=10; // i want to change parameters
list.store.sync();
but it say: 'Uncaught TypeError: Object [object Object] has no method 'writeRecords''
evant
14 Sep 2010, 4:13 AM
store.read();
dbottillo
14 Sep 2010, 4:18 AM
i receive: Uncaught ReferenceError: stcCallback1001 is not defined
dbottillo
16 Sep 2010, 2:14 AM
anyone?
i can't undestand how it works this store
if i load store with this json:
stcCallback1001(
{ results: [ ...
it works
and if i do store.read(); it say 'Uncaught ReferenceError: stcCallback1001 is not defined'
but if i load store then i change json to
stcCallback1002(
{ results: [ ...
and do store.read(); it works!!
so why i have to change number prefix json? i can't change on my own...!
dbottillo
16 Sep 2010, 2:41 AM
after searching i found solution
callbackParam: 'idSession'
so in my back_end i receive stcCallback00XX e then i can create json correctly
(i think there is some lack in documentation about this...!)
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.