前段需求,中间有几个问题困扰了很久没有解决方法

TJkaklf 2018-08-20 05:50:36
需求是这样的,因为js在别的服务器上,所以我需要一个base.html里写原生js,通过xmlhttp来获取js的域名,然后在我的业务的html里引入base.html和js,不能用所有js,包括jquery.
说一下我的做法吧,在base.html使用xmlhttp从后台获取js所在服务器的域名,写一个loadjs的方法,方法参数是js的后半截地址.在业务html里使用link引入base.html,调用loadjs方法.业务html里用到了(funchtion(){})();
这种方法在除了ie浏览器之外都可以用,ie我试了很多方法,都不行,包括iframe,xmlhttp加载base.html
...全文
421 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
TJkaklf 2018-08-28
  • 打赏
  • 举报
回复
没有人help me 么
TJkaklf 2018-08-27
  • 打赏
  • 举报
回复
有没有大佬能不能帮帮我??????????
TJkaklf 2018-08-21
  • 打赏
  • 举报
回复
引用 1 楼 jslang 的回复:
你用的是ie几。最好把代码发一下。

<!DOCTYPE html>
<html>
<head>
<title>##</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script>
init = function() {
var xmlHttp;
window.jsPath = null;
function createxmlHttp() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
xmlHttp = new XMLHttpRequest();
}
}

window.getJSPath = function() {
if (jsPath) {
return jsPath;
}
createxmlHttp();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
jsPath = xmlHttp.responseText;
}
}
};
xmlHttp.open("POST", "../interface/getPATH.jsp", false);
xmlHttp.send(null);
return jsPath;
}
jsPath = getJSPath();
String.prototype.startWith = function(str) {
var reg = new RegExp("^" + str);
return reg.test(this);
}
if (!jsPath.startWith("http")) {
document.write(jsPath);
}
path = jsPath.split(",");
jsPath = path[0];
proPath = path[1];
window.loadscript=function(url/* ,callback */){
var head = document.getElementsByTagName('head')[0];
var script=document.createElement('script');
script.type="text/javascript";
script.async=false;
script.defer=false;
script.src=jsPath+url;
head.appendChild(script);
/* if(callback!=undefined){
callback();
} */
}
/* Skip = {};
Skip.includeJsText = function(rootObject, jsText) {
if (rootObject != null) {
var oScript = document.createElement("script");
oScript.type = "text/javascript";
oScript.text = jsText;
rootObject.appendChild(oScript);
}
}
responseText = null;
Skip.addjs = function(url) {
if (responseText) {
return responseText;
}
createxmlHttp();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
responseText = xmlHttp.responseText;
}
}
};
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
var head = document.getElementsByTagName('head')[0];
Skip.includeJsText(head, responseText);
} */
}
</script>

</head>

<body>
</body>
</html>


<!DOCTYPE html>
<html>

<head>
<meta charset="GBK">
<meta http-equiv="X-UA-Compatible"
content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>SQL</title>
<!-- 引入angular的js -->
<script type="text/javascript">
(function(){
function createxmlHttp() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
xmlHttp = new XMLHttpRequest();
}
}
createxmlHttp();
var ajax = new XMLHttpRequest();
ajax.open("get","base.html",false);
ajax.send(null);
ajax.onreadystatechange = function () {
if (ajax.readyState==4 &&ajax.status==200) {
}
}
var p=window.parent;
window.init();
var array = new Array();
array.push("js/angular.min.js");
array.push("js/angular-cookies.js");
array.push("js/jquery.js");
array.push("js/angularjs/base.js");
array.push("js/angularjs/controller/baseController.js");
array.push("js/angularjs/controller/datatool/dataToolsController.js");
array.push("js/angularjs/service/datatool/dataToolsService.js");
for(var i=0;i<array.length;i++){
/* Skip.addjs(jsPath+array[i]); */
window.loadscript(array[i]/* ,loadscript(array[i+1]) */);
/* i++; */
}
})();
</script>
<!-- <script type="text/javascript" src="http://test.work.soufun.com:8001/oa/platform_web/js/angularjs/controller/datatool/dataToolsController.js"></script>-->
<!--<script type="text/javascript" src="http://test.work.soufun.com:8001/oa/platform_web/js/angularjs/service/datatool/dataToolsService.js"></script> -->
</head>
<body class="oafindsql" ng-app="myApp"
ng-controller="dataToolsController">
<div class="total">
<div class="admin">
<label>数据库用户:</label> <select ng-model="id">
<option value="3">oahz_r_test</option>
</select>
</div>
<br>
<div class="inputSQL">
<label style="align-self: auto">SQL:</label>
<textarea ng-model="sql" placeholder="请输入SQL语句"
style="width:600px;height:40px;"></textarea>
<button ng-click="findsql()">查询</button>
</div>
</div>
<br>
<div>
<label>结果:</label>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td ng-repeat="(key,value) in list[0]">{{key}}</td>
</tr>
<tr ng-repeat="map in list">
<td ng-repeat="(x,y) in map">{{y || " "}}</td>
</tr>
</table>
</div>
</body>

</html>

大哥,帮忙看一下,我弄了半个月了,老项目转前后端分离的
天际的海浪 2018-08-20
  • 打赏
  • 举报
回复
你用的是ie几。最好把代码发一下。

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧