PDA

View Full Version : PHP from ajaxroutine returns text from file not PHP



EricFr8
11-01-2006, 11:48 PM
1) Script Title: ajaxroutine.js

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm

3) Describe problem:

I'm trying to use the ajaxpack.js but running into a problem:

The code is exceedingly simple, taken right from the page:
<script type="text/javascript" src="ajaxroutine.js"></script>
</HEAD>
<BODY>
<div id="test"></div>
<script type="text/javascript">
function processGetPost()
{
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
if (myajax.readyState == 4)
{
if (myajax.status==200 || window.location.href.indexOf("http")==-1)
{
if (myfiletype=="txt")
{
var target = document.getElementById("test");
target.innerHTML=myajax.responseText;
alert(myajax.responseText);
}
else alert("xml" + myajax.responseXML);
}
}
}
ajaxpack.getAjaxRequest("frames.php", "frameName=frame001", processGetPost, "txt");
</script>

Here is my frames.php:

<?php
$frame = $_GET['frameName'];
echo $frame;
?>

The responseText alert shows the complete text of frames.php, not "frame001" as I hoped. I've fooled with it for a couple hours and am frustrated.
I installed Xampp on a Windows XP laptop, which seems to be working fine.

What little gotcha have I missed?

jscheuer1
11-02-2006, 10:11 AM
Did you take care of this part:


from the Demo:

As you can see, the code references an external JavaScript file, which you'll need to download and copy to your web page directory: ajaxroutine.js (http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.js) (right click, and select "Save As"). Installation is complete.

Strangeplant
11-02-2006, 01:52 PM
Sounds to me more like the php script is not executing on the server, but being returned as file content. Is php enabled?

jscheuer1
11-02-2006, 06:20 PM
Sounds to me more like the php script is not executing on the server, but being returned as file content. Is php enabled?

Definitely a possibility considering that 'the server' in this case appears to be a local implementation of some sort:


I installed Xampp on a Windows XP laptop, which seems to be working fine.

If I am reading this right, perhaps Xampp just doesn't do php via Ajax in this manner though, a bona fide php server does. Or, 'seems to be working' isn't the same as 'is working' or maybe Xampp has nothing to do with php. Also, It may be that only some php servers would work with this anyway.

EricFr8
11-03-2006, 07:19 AM
Alright, I figured it out. Well, I found an obscure reference in the Googlepile. Apparently if you're using a Xammp installation locally, you need to reference the localhost directly. Therefore, changing the line:

ajaxpack.getAjaxRequest("frames.php", "frameName=frame001", processGetPost, "txt");

to

ajaxpack.getAjaxRequest("http://localhost/frames.php", "frameName=frame001", processGetPost, "txt");

returns "frame001 instead of the PHP syntax. Go figure.

I presume it will have to be changed back when uploading to my webserver.

Hopefully this will help the next guy.