Results 1 to 5 of 5

Thread: PHP from ajaxroutine returns text from file not PHP

  1. #1
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP from ajaxroutine returns text from file not PHP

    1) Script Title: ajaxroutine.js

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxroutine.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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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 (right click, and select "Save As"). Installation is complete.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    Sounds to me more like the php script is not executing on the server, but being returned as file content. Is php enabled?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Strangeplant
    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:

    Quote Originally Posted by EricFr8
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •