J
Jon Slaughter
When a user clicks a link I have it open up a file in a div using ajax.
my code is
<a href="#Find" onclick="javascript:jah('Find.html','content');">Find</a><br
/>
Where Find.html is an html file on the server. Now when I do this everything
works fine except php code is not being executed.
The jah code is
function jah(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'sending...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {jahDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {jahDone(target);};
req.open("GET", url, true);
req.send();
}
}
}
function jahDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="jah error:\n" +
req.statusText;
}
}
}
The find.html file is something like
<html>
<body>
Find
<?php
echo "Hello";
?>
end Find
</body>
</html>
I get Find and end Find but not hello.
Is there any way to make this work so that the php code is being executed? I
tried using iframes inside the div but there are issues with the size(the
iframe will not expand to fit the div and then there are scrolling issues).
Is it not possible to use php and ajax together like I'm trying to do? (I
figure that the request object is not causing the php excution on the server
side but then it makes it worthless to use ;/)
Thanks,
Jon
my code is
<a href="#Find" onclick="javascript:jah('Find.html','content');">Find</a><br
/>
Where Find.html is an html file on the server. Now when I do this everything
works fine except php code is not being executed.
The jah code is
function jah(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'sending...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {jahDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {jahDone(target);};
req.open("GET", url, true);
req.send();
}
}
}
function jahDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="jah error:\n" +
req.statusText;
}
}
}
The find.html file is something like
<html>
<body>
Find
<?php
echo "Hello";
?>
end Find
</body>
</html>
I get Find and end Find but not hello.
Is there any way to make this work so that the php code is being executed? I
tried using iframes inside the div but there are issues with the size(the
iframe will not expand to fit the div and then there are scrolling issues).
Is it not possible to use php and ajax together like I'm trying to do? (I
figure that the request object is not causing the php excution on the server
side but then it makes it worthless to use ;/)
Thanks,
Jon