为了获取一些内容,我一直对将xmlhttprequests制作到不同的服务器感到困惑.这是我写的,但似乎我在某些方面弄错了..
var URL = new Array();
URL[0] = "http://www.example1.com";
URL[1] = "http://www.example2.com";
URL[2] = "http://www.example3.com";
var nRequest = new Array();
for (var i=0; i<3; i++) {
nRequest[i] = new XMLHttpRequest();
nRequest[i].open("GET", URL[i], true);
nRequest[i].onreadystatechange = function (oEvent) {
if (nRequest[i].readyState === 4) {
if (nRequest[i].status === 200) {
console.log(nRequest[i].responseText);
alert(nRequest[i].responseText);
} else {
console.log("Error", nRequest[i].statusText);
}
}
};
nRequest[i].send(null);
}
Run Code Online (Sandbox Code Playgroud)
在IE10上使用此代码我在控制台上被拒绝访问..
如果我删除数组并使用简单的请求,它按预期运行..
wRequest = new XMLHttpRequest();
wRequest.open("GET", "http://www.example1.com", true);
wRequest.onreadystatechange = function (oEvent) {
if (wRequest.readyState === 4) …Run Code Online (Sandbox Code Playgroud) 我最近从 Wamp(wampserver)搬到了 Docker(Windows 主机)。使用 wamp 时,我能够拥有多个项目,例如以下文件结构
- wamp64
- www/
- project1/
- project2/
- ....
Run Code Online (Sandbox Code Playgroud)
在 wamp 的 Apache 上,我定义了几个虚拟主机,所有项目都使用 wamp 的数据库,每个都有自己的架构。
因此,在必要时通过访问类似 url或相应的虚拟主机来切换上下文从project1、project2到project3等是很常见的http://localhost/projectX。
正如我目前所见,这在 Docker 上似乎并不那么简单。我的第一个方法是在每个项目上设置一个不同的 Docker
- www/
- project1/
- dockerfile & docker-compose
- project2/
- dockerfile & docker-compose
- projectX/
- dockerfile & docker-compose
- data // this is where mysql data lie
Run Code Online (Sandbox Code Playgroud)
我认为,与我习惯使用 wamp 的相比,这似乎不太有效,因为每次我想更改上下文时,我都必须使用docker-compose stop我当前正在工作docker-compose up的项目和我想切换到的项目,反之亦然.
我尝试了另一种方法,在单个 apache-php 容器(整个 www 文件夹)中运行所有项目 …
我正在进行ajax调用,我从中获取内容responseText.
我通过使用alert内部确认,responseText包含整个页面作为string.
没关系.现在,我需要将其转换为DOM并使用提取从字符串具体内容getElementsByTagName,getElementsByName等...
我的问题是这些似乎都不起作用.
我已经阅读了很多关于使用的参考文献responseXML,responseText但是这让我回来了null.
所以,通过坚持responseText,我怎样才能得到我想要的特定元素?
例如,如果我的回复包含以下内容:
<html>
<head>....</head>
<body>....
.....
<table>
<tr>
<td>sometext</td>
<td>someothertext</td>
</tr>
<tr>
<td>sometext</td>
<td>someothertext</td>
</tr>
<tr>
<td>sometext</td>
<td>someothertext</td>
</tr>
</table>
<div> somediv </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如何访问表的第二行及其值?或者div等..所以,现在在我的实际html中,我有这样的感觉
<html>
<head>.....</head>
<body>
<table><tr><td id="test">Test</td></tr></table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我希望在我的实际html表中解析提取的元素/值.
document.getElementById('test').innerHTML = the_extracted_elements_from_responseText