将HTML页面放入div中

时间:2011-06-04 21:41:00

标签: javascript html ajax

如何将window.location放入同一HTML页面的div中?这是我现在拥有的:

function x {
    var httpxml;
    if (window.XMLHttpRequest) {
        httpxml = new XMLHttpRequest();
    }
    else {
        httpxml = new ActiveXObject("Microsoft.XMLHTTP");
    }

    httpxml.open("GET", "Home.aspx", true);
    httpxml.send();

    httpxml.onreadystatechange = function() {
        if (httpxml.status == 200 && httpxml.readyState == 4) {

            // what can i write here to show Home.aspx page into div at default.aspx page
        }
    }
}

2 个答案:

答案 0 :(得分:1)

假设您div iddiv1

if (httpxml.status == 200 && httpxml.readyState == 4) {
    document.getElementById("div1").innerHTML = httpxml.responseText;
}

答案 1 :(得分:0)

你可以简单地使用jQuery。例如:

$('div.class').load('mypage.html');

......或:

$('#mydivID').load('mypage.html');