Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Web Design & Development
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver dvd email error excel excel 2003 firefox hard drive hardware hijackthis internet keyboard laptop malware monitor network networking outlook problem processor ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
call a php script from a javascript

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

 
Thread Tools
snorkytheweasel's Avatar
Computer Specs
Senior Member with 188 posts.
 
Join Date: May 2006
Experience: UNIX/VMS:Elder Geek; DOS/Windows:Fossil
28-Sep-2009, 05:37 PM #1
call a php script from a javascript
I'm trying to get a page to display a series of images, one at a time, and changing the display every n seconds.

I wrote a php routine "rotatepix.php." Using that script I can open the directory and randomly select and display an image. However, php stops as soon as the page is loaded. With each refresh (or opening) of the page, a randomly-selected image displays.

But I want to have javascript take over and keep changing the images.

I think the approach is to use setInterval() to call the php script

Code:
function foo()
{
	var action;
	action="document.open('rotatepix.php')";
	setInterval(action, 500);
}

foo();
and then call that script from the web page. With that I don't get any errors, but I also don't get any results.

As you can see, my js skills suck.

I've looked at some "rotating banners" code, but none seem to fit what I need.

Some notes:
  1. all of the images are in the same directory
  2. all of the server side action takes place on the same server, and that server supports php
  3. the rotatepix.php mentioned above works within PHP's limitations
Can someone get me on the right track? I'd be happy to omit the php if there's a simple js that will accomplish the same goal: pictures selected at random, displayed, and display changed every n seconds
__________________
All of the good signature lines are already taken.
Lordandmaker's Avatar
Computer Specs
Member with 71 posts.
 
Join Date: Sep 2009
Location: London
Experience: Intermediate
01-Oct-2009, 06:59 AM #2
Disclaimer: I'm no JS dev, hardly a PHP one, and I only know linux:

You can't just call a php script to run. It works in apache either through CGI or a php module (and I'd imagine other web servers do similar).
You need to somewhere define where the interpreter for the php script is (i.e. the php binary). Either `php5 rotatepix.php` or tell the OS what to do with *.php files.

You *might* need php5-cli (or equivalent), too. I don't think the default php installer will run from the shell, especialy if it's the apache module one.
Lordandmaker's Avatar
Computer Specs
Member with 71 posts.
 
Join Date: Sep 2009
Location: London
Experience: Intermediate
01-Oct-2009, 07:49 AM #3
Er, I misread that quite spectacularly, apologies for the mostly useless post. I'd be surprised if there weren't several thousand JS image slideshows knocking around on the net, though.
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Senior Member with 183 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
05-Oct-2009, 10:58 AM #4
http://www.w3schools.com/HTMLDOM/met...etinterval.asp cant u just make setintercval() call foo/?
or just make your javascript pre load all the images and then on the set interval make the change of which image is displayed in the div or whatever. <script language="javascript">
function OnMouseOverMainImage(image, mainImage)
{
mainImage.src = image.src;
jsLastMainImage = image.src;
}
function changeme(id, action) {
if (action=="hide") {
document.getElementById(id).style.display = "none";
} else {
document.getElementById(id).style.display = "inline";
}
}
function submitform ( selectedtype )
{

document.sbmtform.submit() ;
}
</script>

that script is for when an image thumbnail is hovered it changes to the big image in the div like on http://www.socialemo.com/item.php and you could use set interval to call the javascript function to show the image. so u dont have to use php at all?

Last edited by emopoops : 05-Oct-2009 11:04 AM.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,519 posts.
 
Join Date: Oct 2006
08-Oct-2009, 12:18 AM #5
Quote:
I've looked at some "rotating banners" code, but none seem to fit what I need.
link to one and ask what you want different.
MRdNk's Avatar
Computer Specs
Senior Member with 413 posts.
 
Join Date: Apr 2007
Experience: Excel, Access, PHP, Js
09-Oct-2009, 06:40 AM #6
Imo, you're looking for an AJAX type solution, checkout the W3Schools page here.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,519 posts.
 
Join Date: Oct 2006
10-Oct-2009, 12:57 PM #7
Quote:
Originally Posted by MRdNk View Post
Imo, you're looking for an AJAX type solution, checkout the W3Schools page here.
w3schools is really, really meh. content is very mediocre and way too many advertisements.

I prefer linking to something like the MDC or to the W3C:

https://developer.mozilla.org/en/AJAX/
https://developer.mozilla.org/en/AJAX/Getting_Started

just my $0.02
Reply Bookmark and Share

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 12:54 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.