javascript中采用jQuery ajax动态加载js文件的解决方法
来源:互联网 发布:oracle java tutorial 编辑:程序博客网 时间:2024/06/15 06:58
var Env = new function () { this.envPath = null; this.getPath = function () { this.envPath = document.location.pathname; this.envPath = this.envPath.substring(0, this.envPath.lastIndexOf("/") + 1); var _scripts = document.getElementsByTagName("script"); var _envPath = null; var _scriptSrc = null; var self_fileName = "FormObject.js"; for (var i = 0; i < _scripts.length; i++) { _scriptSrc = _scripts[i].getAttribute("src"); if (_scriptSrc && _scriptSrc.indexOf(self_fileName) != -1) { break; } } if (_scriptSrc != null) { if (_scriptSrc.charAt(0) == '/') { this.envPath = _scriptSrc.substr(0, _scriptSrc.length - self_fileName.length); } else { this.envPath = this.envPath + _scriptSrc.substr(0, _scriptSrc.length - self_fileName.length); } } } this.getPath(); //导入函数 this.import = function (scriptPath) { var _url = this.envPath + scriptPath; if (_url.indexOf("?") != -1) { _url += "&requestTime=" + (new Date()).getTime(); } else { _url += "?requestTime=" + (new Date()).getTime(); } //alert(_url); $.ajax({ url: _url, dataType: "script", async: false, //同步 cache: false }).done(function () { ; }); }; this.importCache = function (scriptPath) { var _url = this.envPath + scriptPath; if (_url.indexOf("?") != -1) { _url += "&requestTime=" + (new Date()).getTime(); } else { _url += "?requestTime=" + (new Date()).getTime(); } $.ajax({ url: _url, dataType: "script", async: false, //同步 cache: true }).done(function () { ; }); }; this.ajax = function (t_url, t_data, fn_success) { if (t_data) { //输入json数据不为空 $.ajax({ headers: { 'Content-Type': 'application/json' }, type: "get", url: t_url, cache: false, data: t_data, dataType: "json", success: fn_success, error: function (msg) { if (msg) { ShowAlert(msg.responseText); } } }); } else { $.ajax({ headers: { 'Content-Type': 'application/json' }, type: "get", url: t_url, cache: false, dataType: "json", success: fn_success, error: function (msg) { if (msg) { ShowAlert(msg.responseText); } } }); } }; // return this;};//----导入子库 startEnv.import("jsControl.js");
0 0
- javascript中采用jQuery ajax动态加载js文件的解决方法
- jquery动态加载javascript文件的方法
- Ajax动态加载JavaScript文件
- Ajax动态加载JavaScript文件 .
- jquery动态加载js文件
- mvc用js动态加载模拟jquery的.ajax
- jquery中ajax加载js和json文件
- JavaScript动态加载js文件
- javascript动态加载js文件
- javascript中动态加载js文件多种解决办法
- jquery js 动态加载 js文件
- jquery 动态加载js文件以及插件的调用
- 使用jQuery动态加载js脚本文件的方法
- 使用jquery动态加载js,css文件
- 使用jquery动态加载js,css文件
- 使用jquery动态加载js,css文件
- jquery动态加载js/css文件方法
- jquery 动态加载css,js文件
- 金明的预算方案加选课(树上的背包)
- 【数据结构和算法14】归并排序
- django post_save post_delete
- 简单的DP
- export:Command not found
- javascript中采用jQuery ajax动态加载js文件的解决方法
- java设置代理服务器
- 第八周项目二-用对象数组操作长方柱类
- java 数字转换为汉语中人民币的大写
- 重建二叉树
- ArgumentNullException: 值不能为 null问题
- html的元素分类
- Android SO逆向-对象的构造函数与析构函数
- 第一章--ROS机器人操作系统入门简介