ajax not executing php

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
 
R

Rik

Jon Slaughter said:
When a user clicks a link I have it open up a file in a div using ajax..

<a href="#Find"
onclick="javascript:jah('Find.html','content');">Find</a><br
/>

Where Find.html is an html file on the server.
<html>
<body>
Find
<?php
echo "Hello";
?>
end Find
</body>
</html>

I get Find and end Find but not hello.

Probably you do, it's just hidden in the HTML source as raw PHP-code,
because your server isn;t set up to parse *.html for php-code (as ist
should be.

Rename your file & links Find.php
 
J

Jon Slaughter

Jon Slaughter said:
When a user clicks a link I have it open up a file in a div using ajax.

<a href="#Find"
onclick="javascript:jah('Find.html','content');">Find</a><br
/>

Where Find.html is an html file on the server.
<html>
<body>
Find
<?php
echo "Hello";
?>
end Find
</body>
</html>

I get Find and end Find but not hello.

Probably you do, it's just hidden in the HTML source as raw PHP-code,
because your server isn;t set up to parse *.html for php-code (as ist
should be.

Rename your file & links Find.php
--

Oh, I see. Wasn't thinking.

Thanks,
Jon
 

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

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,441
Members
47,101
Latest member
DoloresHol

Latest Threads

Top