使用javascript显示内容

使用javascript显示内容,javascript,xmlhttprequest,Javascript,Xmlhttprequest,快速提问,为什么这不起作用 if ( xmlhttp.responseText ) { location.href = "result.php" document.getElementById( 'page-result' ).innerHTML = xmlhttp.responseText; } 我要做的是将搜索结果放在另一页的div上。通过在查询字符串中传递消息重定向到下一页,如 if ( xmlhttp.responseText ) { locatio

快速提问,为什么这不起作用

if ( xmlhttp.responseText )
{
    location.href = "result.php"
    document.getElementById( 'page-result' ).innerHTML = xmlhttp.responseText;      
}

我要做的是将搜索结果放在另一页的div上。

通过在查询字符串中传递消息重定向到下一页,如

if ( xmlhttp.responseText )
{
    location.href = "result.php?responseText=" + encodeURIComponent(xmlhttp.responseText);
}
在result.php中,根据需要输出参数“responseText”的内容


例如,在php中:

每个HTML页面都是独立的;浏览器在每个页面上都是从一块干净的石板开始的,因此您不能像这样操纵上一页的下一页DOM。您必须使用GET或POST(或cookies或session或…)将信息传递到下一页,并在那里单独处理信息。

正如Juhana所说,这不是jQuery。这是标准的JavaScript。如果您想要jQuery ajax: