Connecting Tech Pros Worldwide Help | Site Map

Javascript and Crons

  #1  
Old September 6th, 2008, 08:50 AM
Familiar Sight
 
Join Date: Sep 2007
Posts: 174
Hi all not sure where to post this question but here it is anyway-

I have a page on my webserver we i view it manually in my browser i can use javascript to automatically actuate a form, i.e. it automatically posts a form to another webpage when it is loaded.

This is a .php page so when the script runs it automatically post this form to another .php which recieves it then process the information.

Now what i want to know is it possible for the javascript on the .php page to work when i run a cron job, cause when i tried it ran the page but didn't seems to run the script.
  #2  
Old September 6th, 2008, 12:21 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: Javascript and Crons


Does the cron use a browser to open the page?
  #3  
Old September 8th, 2008, 07:17 AM
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 410

re: Javascript and Crons


php doesn't run javascript.

you could write a wrapper page and use javascript to resubmit the form on a timeout instead of a chron job.

in win xp, the page can run 24/7 by making it a new active desktop item.
  #4  
Old September 11th, 2008, 07:47 AM
Familiar Sight
 
Join Date: Sep 2007
Posts: 174

re: Javascript and Crons


Sorry for the slow reply got a little distracted,

Anyway the cron does not use a browser, its run by the server;

Also do u know of any php functions that can actuate a button on an event such as a timer.

The idea is the cron job runs the .php page after 20 seconds or so it will imitate someone clicking a button.


Thanks for the help,
  #5  
Old September 11th, 2008, 01:26 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: Javascript and Crons


Why not have a browser window open and use setInterval to simulate clicking the button every 20 seconds?

Even if you use PHP to generate some client-side code, PHP is run on the server, so you can't do this with PHP alone.
  #6  
Old September 11th, 2008, 10:23 PM
Familiar Sight
 
Join Date: Sep 2007
Posts: 174

re: Javascript and Crons


You see i don't mind using something else as well it just that when i run the cron job it won't use the javascript code (not a browser), not sure about other scripts though.

How would i open a browser page on a remote server (the one the script is being hosted on).

And can u give a reference for "setinterval" is it a php function??

Thanks heaps
  #7  
Old September 12th, 2008, 11:40 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: Javascript and Crons


setInterval is a JavaScript function. I meant manually opening the browser on the remote server and then letting it run continuously. Is that an option or are you running it from somewhere else?

A question you could ask yourself is is the JavaScript necessary and can you do without. Can you post the JavaScript code on the page?
  #8  
Old September 13th, 2008, 09:38 AM
Familiar Sight
 
Join Date: Sep 2007
Posts: 174

re: Javascript and Crons


I believe i have found a solution purely with php,

Thanks for all help
  #9  
Old September 13th, 2008, 12:07 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: Javascript and Crons


Glad you found a solution. Makes sense really to go with PHP alone in this case.
Reply