Eexcuting PHP from Javavscript

Discussion in 'PHP' started by billreid, Feb 22, 2010.

  1. #1
    I have a PHP program that does a task for a indeterminant time that I want to kick off in javascript and then contunue the javascript after the PHP is complete. I could put a timer for the lonest time the PHP can take but would be better if we had a way to know the PHP was finisihed.

    Any help appeciated.
     
    billreid, Feb 22, 2010 IP
  2. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #2
    document write PHP my friend told me that it worked for him.
     
    astrazone, Feb 22, 2010 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    In the page with the JS you start an interval, and then point the src of another JS to your PHP page.

    <script type="text/javascript">
    var process = function()
    {
        do_stuff();
    }
    var processing = setInterval(process, 1000);
    </script>
    <script type="text/javascript" src="script.php"></script>
    Code (markup):
    Then in "script.php" you print some javascript that will clear the interval at the end.

    <?php
    do_stuff_in_php();
    echo 'clearInterval(processing);';
    ?>
    Code (markup):
     
    joebert, Feb 22, 2010 IP
  4. billreid

    billreid Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Trying joebert's concept

    function countClickHandler ( )
    {
    if ( document.getElementById("countButton").value == "Click me!" )
    {
    // Start the timer
    document.getElementById("countButton").value = "Enough already!";
    countIntervalId = setInterval ( "count()", 1000 );
    }
    else
    {
    document.getElementById("countMessage").innerHTML = "";
    document.getElementById("countButton").value = "Click me!";
    clearInterval ( countIntervalId );
    }
    }

    function count ( )
    {
    if ( Math.random ( ) > .5 )

    var process = function interval()
    var processing = setInterval(process, 2000);</script>
    <script type="javascript"> src="uhits.php";</script>
    <script type="text/javascript"> document.getElementById("countMessage").innerHTML = "Woo!";
    else

    var process = function interval()
    var processing = setInterval(process, 2000);</script>
    <script type="javascript"> src="uhits.php";</script>
    <script type="text/javascript"> document.getElementById("countMessage").innerHTML = "Yay!";


    setTimeout ( 'document.getElementById("countMessage").innerHTML = ""', 500 );

    }
    </script>

    <div id="countMessage" style="height: 50px; font-size: large; color: red; width: 300px">This is the hits Generator</div>
    <input type="button" name="clickMe" id="countButton" value="Click me!" onclick="countClickHandler()"/>

    Does not execute the uhits.php
     
    billreid, Feb 22, 2010 IP
  5. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #5
    <script type="javascript"> src="uhits.php";</script>
    Code (markup):
    Should be
    <script type="javascript" src="uhits.php"></script>
    Code (markup):
     
    CoreyPeerFly, Feb 22, 2010 IP