Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Execute php page from javascript

    Quote Originally Posted by mlseim View Post
    hmmm .... sort of stumped.

    For a test, I made a script that pulls a random "bumper-sticker" quote
    out of a file and sends it back as Javascript.

    Put this on a test page of yours and see what happens:

    <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script>

    Wherever that line is, when you view your web page, it should have a random quote.

    It's using the same code that I had above (in post #2).
    how would you put <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> into a function for javascript to call this php file?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    I think it would have to be AJAX, a combination of PHP and javascripting.
    You may have to ask this in the javascript forum, as I'm not a javascript expert.


    .

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Moved.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,023
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Since that PHP page returns actual JavaScript code (example, document.write("Is it time for your medication or mine?") , you need to simply drop that line you showed ANY PLACE in your page where you want the text to appear.

    Just as a simple example:
    Code:
    ....
    <span style="font-size: large; color: red;">
    <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script>
    </span>
    ...
    There are other, more eloquent ways to use content from PHP pages, but given what you already have there, this is about the only useful way to do it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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