ext 中 ajax怎么异步加载js文件 ? 谁能提供下代码?
[b]问题补充:[/b]
想找个一好用的的 我找了个 不知道为什么加载js 总是失败,偶尔也能成功
[code="java"]
var jsStr = "";
Ext.Ajax.request( {
// method : 'POST',
url : "pages/UnitsInfo.js",
//scope : this,
success : function(response) {
jsStr += response.responseText;// 把每次加载的内容都存入jsStr中
// 获取模块类
this[node.id] = eval(jsStr);
// 实例化模块类
model = new this[node.id]();
tab.on('destroy', function() {
model.destroy();
});
},
failure : function(response) {
Ext.Msg.show( {
title : "错误信息",
msg : "加载页面核心文件时发生错误!",
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
});[/code]
this[node.id] = eval(jsStr);
这句可能有2个错误:
1 你把//scope : this, 注释掉了,那么这里的this指的是Ext.Ajax这个对象了,而非你想象的自己的某个对象;
2 使用eval是有问题的,eval以后js里面的对象和变量是局部的(除非你定义时没有加 var显式声明)。IE下可以window.execScript;firefox下可以window.eval
这个其实和ext没有多大关系.主要是和javascript有关系.
异步加载的方法网上很多的.我帮你找吧.哎
[url]http://hi.baidu.com/usxue/blog/item/c674e91e8ed0fe1a40341763.html[/url]
[url]http://www.cnblogs.com/baixingfa/archive/2009/01/15/1376072.html[/url]
[url]http://www.google.cn/search?hl=zh-CN&q=%E5%BC%82%E6%AD%A5%E5%8A%A0%E8%BD%BD+js%0D%0A&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=f&oq=[/url]