[英]Javascript not loading another page into DIV
I am having some troubles today. 我今天遇到了一些麻烦。 I am trying to get Javascript to load content into a <div>
. 我想让Javascript将内容加载到<div>
。 Now, this is my JavaScript source code: 现在,这是我的JavaScript源代码:
function loadXMLDoc(filename) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
after_load_function(xmlhttp.responseText);
}
}
xmlhttp.open("GET", filename, true);
xmlhttp.send();
}
function after_load_function(responseText) {
document.getElementById("right").innerHTML = responseText;
}
window.onload = function () {
loadXMLDoc("welcome.html");
}
And my div: 我的div:
<div id="right"></div>
Does anyone know the problem? 有谁知道这个问题?
Just had a similar issue, here is what I have and it seems to be working really well, 刚刚遇到类似的问题,这就是我所拥有的,它似乎工作得非常好,
HTML: HTML:
<html>
<head>
<title> pageOne </title>
<script src="jquery-1.11.1.min.js"></script>
</head>
<body>
<input class='loadBtn' type='submit' value='Load a Different Page!:'>
<div id="page"></div>
</body>
</html>
JS: JS:
//click function:
$(".loadBtn").click(function(){
//div to hide/replace
$('#page')
//fadeOut div content:
.delay(200).fadeOut('slow')
//load method:
.load
//url #divToReplace
('pageTwo.php #page')
//fadeIn new div content:
.hide().delay(300).fadeIn('slow');
//prevent default browser behavior
return false;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.