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 acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network operating system printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
call a php script from a javascript

Reply  
Thread Tools
snorkytheweasel's Avatar
Computer Specs
Member with 215 posts.
 
Join Date: May 2006
Experience: UNIX/VMS:Elder Geek; DOS/
28-Sep-2009, 06: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
__________________
stw
Certified Digital Forensics Examiner, MCSE, Official Windows Crash Test Dummy, etc., etc.
Nature: Nerd. Nurture:Linux
Lordandmaker's Avatar
Computer Specs
Member with 71 posts.
 
Join Date: Sep 2009
Location: London
Experience: Intermediate
01-Oct-2009, 07: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, 08: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
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
05-Oct-2009, 11: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 at 12:04 PM..
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
08-Oct-2009, 01: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
Member with 439 posts.
 
Join Date: Apr 2007
Location: UK
Experience: Damn I'm good!
09-Oct-2009, 07:40 AM #6
Imo, you're looking for an AJAX type solution, checkout the W3Schools page here.
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
10-Oct-2009, 01: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

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:44 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.