-2

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

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

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

4

2 回答 2

0

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

if ( xmlhttp.responseText )
{
    location.href = "result.php?responseText=" + encodeURIComponent(xmlhttp.responseText);
}

在 result.php 中,将参数“responseText”的内容输出到任何你想要的地方。

前任。在 php 中:<?php echo $_GET["responseText"]; ?>

于 2012-07-23T14:30:26.813 回答
0

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

于 2012-07-23T14:30:45.167 回答