Connecting Tech Pros Worldwide Forums | Help | Site Map

remotely including php script output via javascript

Tony Rice
Guest
 
Posts: n/a
#1: Jul 23 '05
I've got a simple php script that dumps some database info out that I would
like to make available to others for inclusion on their web pages.
Problem is some of them dont have access to PHP or CGI.

Would this be possible with javascript?

Randy Webb
Guest
 
Posts: n/a
#2: Jul 23 '05

re: remotely including php script output via javascript


Tony Rice wrote:
[color=blue]
> I've got a simple php script that dumps some database info out that I would
> like to make available to others for inclusion on their web pages.
> Problem is some of them dont have access to PHP or CGI.
>
> Would this be possible with javascript?[/color]

<script type="text/javascript" src="URLToYourPHPScript.php"></script>

And have the PHP script output it as a script variable, and then the
client can read the variables.


--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Ray Morgan
Guest
 
Posts: n/a
#3: Jul 23 '05

re: remotely including php script output via javascript


Randy Webb <hikksnotathome@aol.com> wrote:
[color=blue]
>Tony Rice wrote:
>[color=green]
>> I've got a simple php script that dumps some database info out that I would
>> like to make available to others for inclusion on their web pages.
>> Problem is some of them dont have access to PHP or CGI.
>>
>> Would this be possible with javascript?[/color]
>
><script type="text/javascript" src="URLToYourPHPScript.php"></script>
>
>And have the PHP script output it as a script variable, and then the
>client can read the variables.[/color]

Alternatively, if the data on which the script is based doesn't change
too frequently, you can save your server a little work by periodically
writing a static .js file using a cron job. Be sure to serve the
correct http headers with the .js file to indicate when the data will
expire so UAs are advised when to fetch a fresh copy.

On the other hand, since URLToYourPHPScript.php is likely to get
cached, if the data changes in real time and the client must always
receive the latest data, they should append some query string to the
url like "URLToYourPHPScript.php?t=<timeInMilliseconds> ". (The query
string itself isn't used by the PHP script, but it forces a fresh load
of the file.)

--
Ray Morgan
http://Fares-Fair.com/
Tony Rice
Guest
 
Posts: n/a
#4: Jul 23 '05

re: remotely including php script output via javascript


Ray Morgan <-@Fares-Fair.com> wrote in
news:lj57c09aemip6g58ohruaj176n0lec08pa@4ax.com:
[color=blue][color=green]
>>Tony Rice wrote:
>>[color=darkred]
>>> I've got a simple php script that dumps some database info out that
>>> I would like to make available to others for inclusion on their web
>>> pages. Problem is some of them dont have access to PHP or CGI.
>>>
>>> Would this be possible with javascript?[/color]
>>
>><script type="text/javascript" src="URLToYourPHPScript.php"></script>
>>
>>And have the PHP script output it as a script variable, and then the
>>client can read the variables.[/color]
>
> Alternatively, if the data on which the script is based doesn't change
> too frequently, you can save your server a little work by periodically
> writing a static .js file using a cron job. Be sure to serve the
> correct http headers with the .js file to indicate when the data will
> expire so UAs are advised when to fetch a fresh copy.
>
> On the other hand, since URLToYourPHPScript.php is likely to get
> cached, if the data changes in real time and the client must always
> receive the latest data, they should append some query string to the
> url like "URLToYourPHPScript.php?t=<timeInMilliseconds> ". (The query
> string itself isn't used by the PHP script, but it forces a fresh load
> of the file.)[/color]

Thanks to both of you for the information. The last part is especially
useful because the PHP script in question outputs "this day in history"
information which is obviously time sensitive.
Closed Thread