load in a php page from javascript

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");
?>
 
A

acord

acord said:
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");
?>

Hi,

This is the main php script used to initiate the execution:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mailout Campaign Profiling</title>

<link href="css/default.css" rel="stylesheet" type="text/css">

<script src="lib/ajax.js" language="JavaScript"
type="text/javascript"></script>
<base target="contentframe"></base>
</head>
<body>
<table cellpadding="0" cellspacing="0" width="997" align="left">
<tr valign="top">
<!-- START: Tree Menu -->
<td style="background-color:#FFFFFF; border-right:1px
solid #999999;">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"></meta>
<link rel="stylesheet" href="layersmenu-demo.css" type="text/css"></link>
<link rel="stylesheet" href="layerstreemenu.css" type="text/css"></link>

<link rel="shortcut icon" href="LOGOS/shortcut_icon_phplm.png"></link>
<title>The PHP Layers Menu System</title>
<script language="JavaScript" type="text/javascript">
<!--
<?php include ("libjs/layersmenu-browser_detection.js"); ?>
// -->
</script>
<script language="JavaScript" type="text/javascript"
src="libjs/layerstreemenu-cookies.js"></script>

<base target="contentframe"></base>
<div id="treemenu">
</div>
</td>
<!-- END: Tree Menu -->
<td>
<base target="contentframe"></base>
<div id="rightContent">
<!-- load in content at the end of this file -->
</div>
</td>
</tr>
</table>
</body>

<script language="JavaScript" type="text/javascript">
javascript:ajaxpage('treemenu.php', 'treemenu');
javascript:ajaxpage('right-content.html', 'rightContent');
</script>

</html>
 
H

Hywel Jenkins

javascript:ajaxpage('treemenu.php', 'treemenu');

Why have you got the "javascript:" prefix within your JavaScript?

Considering your PHP always seems to output the same stuff, why not just
include it?

I would have been wise to have included a URL where this code can be
seen in action, especially as you haven't mentioned what the error is.
 
H

Hywel Jenkins

<snipped a load of rather badly written code />

So what? From the code you've posted how are we to determine what your
PHP script outputs?
 
A

acord

Hywel said:
Why have you got the "javascript:" prefix within your JavaScript?

Considering your PHP always seems to output the same stuff, why not just
include it?

I would have been wise to have included a URL where this code can be
seen in action, especially as you haven't mentioned what the error is.
Hi

I have just removed the "javascript:", but it doesn't make any
difference. How to include php (to put its output) in the div section?

Sorry I m more than happy to show the public URL, there is no public
URL, I m developing this in my private network.

Thanks
A
 
A

acord

Hywel said:
<snipped a load of rather badly written code />

So what? From the code you've posted how are we to determine what your
PHP script outputs?
It's always difficult (or impossible) to show the output of the php
code, coz the output invoke other javascript libs. I found that if I use
javascript (ajaxpage()) to load the php script into the div treemenu
section, the php code will not call the javascript functions. But if I
put the php codes inside the div treemneu section, the php code invoke
the javascript functions (from the lib), then I can click the tree node
of the menu.

I suspect there is some sequential order when using javascript invoke
the php script in a html file. In my example, I created html script,
then defined a div treemenu, then load the php script at the end of the
html script, eg:

<HTML>
....
<div id="treemenu">
</div>

<script language="JavaScript" type="text/javascript">
ajaxpage('treemenu.php', 'treemenu');
</script>

</HTML>

I created this file with php extention, (eg. test8.php).
I suspect this order is not right. I also tried .html file extention
name, but still not help.

Thanks
A
 
A

acord

acord said:
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");
?>
Hi,

I m actually using PHP Layers Menu System 3.2.0.
I tried to change the iframe to div, but I encountered the above problem.

thanks
A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top