ajaxを使用して、div内に別のページをロードしたページの変数に直接アクセスする方法を探しています。ある種の get 文字列を使用してそれを Javascript に渡し、それを使用して息子のページを開き、get 通常の GET 関数を使用して変数を取得できることを知っています。より良い解決策を探しています。私はこの親ページを持っています:
<body onLoad="control_post_data(<?php
echo true;
//echo isset($_COOKIE['username']); // allow after login is done
?>)">
<div id="publish_page">
</div>
これはスクリプトです:
function control_post_data(bool){
var div = document.getElementById("publish_page");
var xmlhttp = createXmlHttpRequestObject();
if(bool){
//user is registered presend post page
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var responseText = xmlhttp.responseText;
div.innerHTML = responseText;
//Use the response text to add the extra row
}
}
xmlhttp.open("GET","sub_published.php",true);
xmlhttp.send();
} else {
//present log in/register page
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var responseText = xmlhttp.responseText;
div.innerHTML = responseText;
//Use the response text to add the extra row
}
}
xmlhttp.open("GET","login.php",true);
xmlhttp.send();
}
}
sub_published.php ページの親ページ変数にアクセスしようとしています。