A
acord
Hi,
In a html page, I don't know how to load in a php page from javascript.
I've already defined a <div id="treemenu"> in the html page. The
executed content from the php script is supposed loaded into the
treemenu div. What is the best way to achieve this? I got error where
the treemenu didn't close/open on the treenode, as when I clicked on the
treenode, it said Object not found. But if I don't use ajaxpage()
javascript function, and copy the content of the php script under the
<div id="treemenu"> section, the treemenu works well.
Here is the javascript functions I m using to load a php script:
function ajaxpage(url, containerid)
{
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}
function loadpage(page_request, containerid)
{
if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
In html page, I used the following line to load a php page:
<script language="JavaScript" type="text/javascript">
javascript:ajaxpage('treemenu.php', 'treemenu');
</script>
The following script is treemenu.php:
<?php
include ("lib/PHPLIB.php");
include ("lib/layersmenu-common.inc.php");
include ("lib/treemenu.inc.php");
$mid = new TreeMenu();
$mid->setMenuStructureFile("treemenu.txt");
$mid->parseStructureForMenu("Treemenu");
$mid->newTreeMenu("Treemenu");
$mid->printTreeMenu("Treemenu");
?>
In a html page, I don't know how to load in a php page from javascript.
I've already defined a <div id="treemenu"> in the html page. The
executed content from the php script is supposed loaded into the
treemenu div. What is the best way to achieve this? I got error where
the treemenu didn't close/open on the treenode, as when I clicked on the
treenode, it said Object not found. But if I don't use ajaxpage()
javascript function, and copy the content of the php script under the
<div id="treemenu"> section, the treemenu works well.
Here is the javascript functions I m using to load a php script:
function ajaxpage(url, containerid)
{
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}
function loadpage(page_request, containerid)
{
if (page_request.readyState == 4 && (page_request.status==200 ||
window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
In html page, I used the following line to load a php page:
<script language="JavaScript" type="text/javascript">
javascript:ajaxpage('treemenu.php', 'treemenu');
</script>
The following script is treemenu.php:
<?php
include ("lib/PHPLIB.php");
include ("lib/layersmenu-common.inc.php");
include ("lib/treemenu.inc.php");
$mid = new TreeMenu();
$mid->setMenuStructureFile("treemenu.txt");
$mid->parseStructureForMenu("Treemenu");
$mid->newTreeMenu("Treemenu");
$mid->printTreeMenu("Treemenu");
?>