PDA

View Full Version : Ext.ux.includeJS



Gabor Turi
1 Dec 2008, 2:43 PM
Hi, I am useful nowhere simple synchronous Ajax calls, but sometimes I need JavaScript file load during running. A plain solution: (only with ext-base.js)

Ext.ux.includeJS = function(uri) {
var o = Ext.lib.Ajax.getConnectionObject();
if (!o) { return null; }
o.conn.open('GET', uri, false);
o.conn.send(null);
Ext.lib.Ajax.handleTransactionResponse(o, {success:function(req){eval(req.responseText);}});
};
Can be looked at here: http://www.stack.hu/extjs/include.html


Usage:


Ext.namespace('Ext.ux');
Ext.ux.includeJS = function(uri) {
var o = Ext.lib.Ajax.getConnectionObject();
if (!o) { return null; }
o.conn.open('GET', uri, false);
o.conn.send(null);
Ext.lib.Ajax.handleTransactionResponse(o, {success:function(req){eval(req.responseText);}});
};
var include = Ext.ux.includeJS;

console.log('-----');
include('1.js');
console.log('-----');
include('2.js');
console.log('-----');
Result:


console.log: -----
console.log: This is the first JavaScript file
console.log: -----
console.log: This is second file
console.log: -----

jay@moduscreate.com
2 Dec 2008, 6:56 AM
Awesome :)