sencha touch ajax params,extjs - sencha touch override ext.ajax - Stack Overflow

I'm writing a sencha touch app using sencha architect. Because my app do lot of ajax request, most of it need to send 'token' in request header for authentication. So I think of create child class base on Ext.Ajax which always has 'token' in request header. Then I can use this child class without care of the header.

MyApp.override.Ajax.request({ ... })

I try define this in app/override/Ajax.js

Ext.define('Myapp.override.Ajax', {

override: 'Ext.Ajax',

headers: {

'token': 'test'

}

});

I also set this as 'requires' in Application. But get error when try to call

Myapp.override.Ajax.request({ ... })

Seem Myapp can not locate .override package (MyApp.override is undifined)

How to let MyApp know override package or what is the correct/best way to do this.

A quick example is very appreciated. Thank you very much.

Update info:

override file location: app\override\Ajax.js

html file:

var Ext = Ext || {};

Ext.theme = {

name: "Default"

};

app.js file

Ext.Loader.setConfig({

});

Ext.application({

requires: [

'MyApp.override.Ajax'

],

views: [

'ContactDetailView'

],

name: 'MyApp'

...

App can start without error, but when call MyApp.override.Ajax.request : Cannot read property 'Ajax' of undefined , mean MyApp.override is undefined

Update

Here something news, it better but not working yet.

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 );

}

});

and error when try MyApp.Ajax.request() . I'm sure that options.url is exist in options by check the log

[ERROR][Ext.data.Connection#request] No URL specified

I add extend from constructor function

constructor : function (config, url)

{

config = config || {};

//config.url = 'google.com';

this.initConfig(config);

this.callParent(config);

},

Error just disappear when I remove comment from config.url = 'google.com'; but it comes that the config.url there is ajax request url but local file url ??? I see from chrome console and network ?

GET file:///C:/MyApp/assets/www/google.com?_dc=1370855149720

Please help. thanks.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值