Ang*_*ppe 1 html javascript ajax xmlhttprequest request
我正在尝试制作一个XMLHttpRequest从外部文件加载 HTML 并将文件内容插入到div.
当我运行该函数时,它会在所有不够充分的正文中插入 HTML。
我的代码:
--------------------------> HTML <--------------------- -----
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="shit.js" charset="utf-8"></script>
<link rel="stylesheet" href="index.css">
<title>Test</title>
</head>
<body>
<button type="button" name="button" onclick="send()">Click me</button>
<div class="view" id="view"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
--------------------------> CSS <--------------------- -----
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="shit.js" charset="utf-8"></script>
<link rel="stylesheet" href="index.css">
<title>Test</title>
</head>
<body>
<button type="button" name="button" onclick="send()">Click me</button>
<div class="view" id="view"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
--------------------------> JS <--------------------- -----
.view {
margin-top: 5vh;
height: 15vh;
width: 80vw;
background-color: #c1c1c1;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
小智 5
<html>
<head>
<script>
var request;
function sendInfo() {
var url = "NewFile1.html";
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
try {
request.onreadystatechange = getInfo;
request.open("GET", url, true);
request.send();
}
catch (e) {
alert("Unable to connect to server");
}
}
function getInfo() {
if (request.readyState == 4) {
var val = request.responseText;
document.getElementById('chiru').innerHTML = val;
}
}
</script>
</head>
<body>
<marquee><h1>This is an example of ajax</h1></marquee>
<form name="vinform">
<input type="button" value="ShowTable" onClick="sendInfo()">
</form>
<span id="chiru"> </span>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9214 次 |
| 最近记录: |