【问题标题】:using javascript to display content使用 javascript 显示内容
【发布时间】:2012-07-21 19:17:36
【问题描述】:

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

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

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

【问题讨论】:

标签: javascript xmlhttprequest


【解决方案1】:

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

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

在result.php中,任意输出“responseText”参数的内容。

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 2012-11-10
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      相关资源
      最近更新 更多