php generate HTML, but being called by javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • c.l.rogers@cox.net

    #1

    php generate HTML, but being called by javascript

    I've been searching for few days trying to find an answer to my
    question... hopefully I ofund the right place to help me out!

    What I am trying to do is use javescript inside column of a <table>
    tag, to call a php file that will fill in the contents for my column
    and the html page will then finish loading... For example:


    <html>
    <tr>
    <td valign="top">
    <script type="text/javascript"
    src="dir/external.php?"> </script>
    <script language="" type="text/javascript">
    <!--
    for (x = 0; x < 10; x++)
    {
    document.writel n("<a href=data returned from php call >

    </a>");
    }
    //-->
    </script>
    </td>
    </tr>
    </html>


    To give you all a background of what I am doing is, I am using
    MagpieRSS to parse out my XML file and I would like to have my php file

    generate an array of data from the parsed file to return back to the
    javascript in my HTML file and use it to fill in my column... make
    sense?


    Thanks in advance for any help!


    Regards,


    Me

  • Jerry Stuckle

    #2
    Re: php generate HTML, but being called by javascript

    c.l.rogers@cox. net wrote:
    I've been searching for few days trying to find an answer to my
    question... hopefully I ofund the right place to help me out!
    >
    What I am trying to do is use javescript inside column of a <table>
    tag, to call a php file that will fill in the contents for my column
    and the html page will then finish loading... For example:
    >
    >
    <html>
    <tr>
    <td valign="top">
    <script type="text/javascript"
    src="dir/external.php?"> </script>
    <script language="" type="text/javascript">
    <!--
    for (x = 0; x < 10; x++)
    {
    document.writel n("<a href=data returned from php call >
    >
    </a>");
    }
    //-->
    </script>
    </td>
    </tr>
    </html>
    >
    >
    To give you all a background of what I am doing is, I am using
    MagpieRSS to parse out my XML file and I would like to have my php file
    >
    generate an array of data from the parsed file to return back to the
    javascript in my HTML file and use it to fill in my column... make
    sense?
    >
    >
    Thanks in advance for any help!
    >
    >
    Regards,
    >
    >
    Me
    >
    You can't do it like you want. PHP is executed on the server, before
    the page loads. Javascript is executed on the client, after the page
    loads. By the time your javascript starts executing, all of your PHP
    code has been executed.

    Two ways to go about this - either write all the data to the page as
    javascript code (i.e a javascript array), or use AJAX to call PHP back
    on the server.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • c.l.rogers@cox.net

      #3
      Re: php generate HTML, but being called by javascript

      Thanks for the reply!

      Comment

      Working...