I am writing a sencha touch application using the sencha architect. Since my application executes many ajax requests, most of them need to send a “token” to the request header for authentication. Therefore, I am thinking of creating a base of child classes on Ext.Ajax, which always has a “token” in the request header. Then I can use this child class without worrying about the header.
MyApp.override.Ajax.request({ ... })
I am trying to define this in app / override / Ajax.js
Ext.define('Myapp.override.Ajax', {
override: 'Ext.Ajax',
headers: {
'token': 'test'
}
});
I also set this as “required” in the application. But get an error when you try to call
MyApp.override.Ajax.request({ ... })
Seem Myapp cannot find .override package (MyApp.override unifined)
How to let MyApp know the override package or what is the right / best way to do it.
A quick example is much appreciated. Thank you very much.
Update info:
: app\override\Ajax.js
html :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script>
var Ext = Ext || {};
Ext.theme = {
name: "Default"
};
</script>
<script src="sencha-touch-all-debug.js"></script>
<link rel="stylesheet" href="resources/css/sencha-touch.css">
<script src="app/override/Ajax.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>
app.js
Ext.Loader.setConfig({
});
Ext.application({
requires: [
'MyApp.override.Ajax'
],
views: [
'ContactDetailView'
],
name: 'MyApp'
...
, MyApp.override.Ajax.request: Ajax undefined, MyApp.override - undefined
- , , .
Ext.define('MyApp.Ajax', {
extend: 'Ext.data.Connection',
singleton: true,
request: function( options ) {
this.constructor(options, options.url);
console.log(options);
options.header = {'Token':'mytoken'};
this.callParent( options );
}
});
MyApp.Ajax.request(). , options.url ,
[ERROR][Ext.data.Connection#request] No URL specified
constructor : function (config, url)
{
config = config || {};
this.initConfig(config);
this.callParent(config);
},
, config.url = 'google.com'; config.url ajax url url ??? ?
GET file:///C:/MyApp/assets/www/google.com?_dc=1370855149720
, . .