簡単な質問ですが、なぜこれが機能しないのですか?
if ( xmlhttp.responseText )
{
location.href = "result.php"
document.getElementById( 'page-result' ).innerHTML = xmlhttp.responseText;
}
私がやりたいのは、検索結果を別のページの div に入れることです。
簡単な質問ですが、なぜこれが機能しないのですか?
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で:<?php echo $_GET["responseText"]; ?>
各 HTML ページは独立しています。ブラウザーは各ページの白紙の状態から開始されるため、このように前のページから次のページの DOM を操作することはできません。GET または POST (または Cookie またはセッションなど) を使用して次のページに情報を渡し、そこで情報を個別に処理する必要があります。