...

View Full Version : Execute php page from javascript



johnboy0072006
09-06-2011, 10:36 AM
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?

mlseim
09-06-2011, 04:00 PM
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.


.

Inigoesdr
09-06-2011, 10:33 PM
Moved.

Old Pedant
09-06-2011, 11:23 PM
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:


....
<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum