ajax not executing php

Discussion in 'Javascript' started by Jon Slaughter, Mar 8, 2007.

  1. 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
     
    Jon Slaughter, Mar 8, 2007
    #1
    1. Advertising

  2. Jon Slaughter

    Rik Guest

    Jon Slaughter <> wrote:

    > 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
    --
    Rik Wasmus
    Posted on Usenet, not any forum you might see this in.
    Ask Smart Questions: http://tinyurl.com/anel
     
    Rik, Mar 8, 2007
    #2
    1. Advertising

  3. "Rik" <> wrote in message
    news:eek:p.tou9ryviqnv3q9@misant...
    Jon Slaughter <> wrote:

    > 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
     
    Jon Slaughter, Mar 8, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. minnie
    Replies:
    1
    Views:
    737
    Andrew Thompson
    Dec 13, 2006
  2. Nospam
    Replies:
    28
    Views:
    4,641
    Nospam
    Oct 16, 2006
  3. Rajive Narain
    Replies:
    0
    Views:
    2,017
    Rajive Narain
    Sep 18, 2009
  4. Nautilus
    Replies:
    2
    Views:
    179
    Nautilus
    Oct 13, 2004
  5. Dan Anderson

    Executing Perl from PHP

    Dan Anderson, Nov 21, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    107
    James Willmore
    Nov 22, 2003
Loading...

Share This Page