这是我使用 ajax 将外部页面放入 div 的代码 我尝试的是我点击按钮我必须在 div 中显示响应 但我尝试了几次但没有用。 我的 javascript 代码是
var rootdomain="http://"+window.location.hostname
function ajaxinclude(url) {
var url=rootdomain+url;
alert(url);
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.open('GET', url, false) //get page synchronously
page_request.send(null)
writecontent(page_request)
}
function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
document.getElementById("eee").innerHTML=(page_request.responseText);
}
这是我的正文部分:-----
<input type="button" onclick="ajaxinclude('/songcake/index.php')" value="Click !" />
<div id="eee" style=" width:400px; height:800px;">
</div>
请帮忙
谢谢。
最佳答案
使用 jQuery,你可以做类似的事情
$.get('/songcake/index.php', function(data) { $("#eee").html(data); });
关于javascript - 如何在div中调用远程页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3116001/