Reputation: 345
I want to package a Sencha Touch app to deploy to multiple mobile platforms (iOS/Android). I know that cross-domain AJAX requests are not possible for browsers, but is it possible to make cross-domain AJAX calls in a Sencha Touch app? (no server, and packaged to iOS/Android using something like PhoneGap)
I want to hit a third-party API within the Sencha Touch app using AJAX but I'm under the impression that I need a server to wrap the third-party API to avoid the cross-domain issue. Someone please clarify.
Upvotes: 1
Views: 381
Reputation: 465
As A1rPun says Cross-domain AJAX requests are possible with JSONP(JSON with Padding) using Ext.data.proxy.JsonP
Sencha touch-2 Approach:
Ext.define('YourStore', {
extend: 'Ext.data.Store',
config: {
fields: ['field1', 'field2', 'field3'],
proxy: {
type: 'jsonp',
url:'YourUrl',
callbackKey: 'jsoncallback',
extraParams : {
method : 'YourUrl.method',
api_key : 'PUTYOURKEYHERE',
format : 'json',
nojsoncallback : 1
},
reader: {
type: 'json'
}
}
}
});
Upvotes: 0
Reputation: 6055
You can use JSONP, but you can also use normal JSON.
The phones browser will allow cross domain requests when the files are "local" ie wrapped in phonegap.
Upvotes: 0
Reputation: 16857
Cross-domain AJAX request are possible with JSONP
using a Ext.data.proxy.JsonP
.
I don't know what your API looks like but use it something like this:
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
//model: , //Your API
proxy: {
type: 'jsonp',
url : 'http://domain.com/request',
callbackKey: 'theCallbackFunction'
}
});
Upvotes: 1