homepage Welcome to WebmasterWorld Guest from 50.19.172.0
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
True interactivity with php
Running code after the page has finished loading?
andyd273

5+ Year Member



 
Msg#: 3684079 posted 2:18 pm on Jun 26, 2008 (gmt 0)

Is it possible to run PHP after a page has finished loading completely?

The only way that I've found to do it is to make a form with a hidden variable, and then use javascript to set the variable and submit the form which reloads the page, and then have PHP check if the post variable is set when the page reloads.

test.php
<?
if(isset($_POST['test'])){

echo "you pushed the button!";

}else{

?>
<form name="t" method="post" action="test.php">
<input type="hidden" name="test" />
<input type="button" onclick="javascript:document.t.test.value='ok';document.t.submit();" />
<!-- Yes, I realize that I don't have to use javascript in this instance, but its just an example of a deeper problem -->
</form>
<?
}

?>

It would be really nice if you could just use runat=server or some kind of script to just call a php function without reloading the page.

Am I just missing something?

 

dreamcatcher

WebmasterWorld Senior Member dreamcatcher us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3684079 posted 2:27 pm on Jun 26, 2008 (gmt 0)

Ajax is the way to go.

dc

andyd273

5+ Year Member



 
Msg#: 3684079 posted 2:50 pm on Jun 26, 2008 (gmt 0)

Ajax is pretty, but some of the things I want to do involve getting and setting information to a database, which PHP is pretty good at, and it would be nice to be able to do stuff without having to reload the page every time.

Maybe it's time to learn ASP.net

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3684079 posted 2:53 pm on Jun 26, 2008 (gmt 0)

That won't change anything. HTTP is a stateless prototcol. Getting information requires a round trip to the server and the server side processing can be whatever you choose to use, whether that be PHP or ASP. Ajax is JavaScript. Basically you are loading only a part of the page, not the entire page contents all over again when you use AJAX or other related client-side coding techniques.

andyd273

5+ Year Member



 
Msg#: 3684079 posted 3:32 pm on Jun 26, 2008 (gmt 0)

hmm, ok

It would be nice if there was a way to make it not stateless in the future, but in the mean time it's good to know that there really isn't a better way to be doing it that I've been missing.

I use some ajax, but as you say it's just javascript, and client side, and therefore it's limited on what you can do with it.

I wonder how long it will be before someone develops a client side/server side language that can be both interactive with the user and accomplish real stuff on the server.

It would need to run client side, but be able to make calls to server side functions and get data back without reloading the page all over again...

RonPK

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3684079 posted 4:07 pm on Jun 26, 2008 (gmt 0)

It would need to run client side, but be able to make calls to server side functions and get data back without reloading the page all over again...

That is exactly what AJAX does. To be precise: with AJAX you can have JavaScript call a script on the server and parse the server's reply.

[edited by: RonPK at 4:09 pm (utc) on June 26, 2008]

WesleyC

5+ Year Member



 
Msg#: 3684079 posted 4:29 pm on Jun 26, 2008 (gmt 0)

Look up the YUI library, and take a look at the Connection Manager. That should give you a starting point.

There are other libraries out there, but since I use YUI all over the place anyway... :)

andyd273

5+ Year Member



 
Msg#: 3684079 posted 4:57 pm on Jun 26, 2008 (gmt 0)

I'll definitely look into that.
I always enjoy learning something new, especially because I never really thought of ajax to do anything other than make stuff look pretty and move around the page.

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3684079 posted 6:18 am on Jun 27, 2008 (gmt 0)

>> I never really thought of ajax to do anything other than make stuff look pretty and move around the page

While AJAX uses JavaScript they aren't the same thing. From what I understand, you have used JavaScript to make stuff look pretty ;) AJAX isn't one scripting language, but multiple technologies working together. If you are looking for a nice PHP/AJAX tutorial I really like Rasmus' one here: [news.php.net...]

RonPK

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3684079 posted 8:27 am on Jun 27, 2008 (gmt 0)

It is not a bad overview, apart from these lines:

var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){

Browser sniffing s***s, as UA strings can be tampered with. It's better to use object detection to decide which object to use (duh).

webfoo

5+ Year Member



 
Msg#: 3684079 posted 6:47 pm on Jun 27, 2008 (gmt 0)

I use some ajax, but as you say it's just javascript, and client side, and therefore it's limited on what you can do with it.

No, it's not as limited as you seem to believe. Google uses AJAX in Gmail, Google Maps, Google Suggest, iGoogle, Google Calendar, and a number of other complex applications.

andyd273

5+ Year Member



 
Msg#: 3684079 posted 8:54 pm on Jun 27, 2008 (gmt 0)

Well webfoo,
I am starting to see the errors of my thinking.
I do know that Google uses ajax in those things, but I guess I didn't realize it used them to interact with the server.
Now, Google suggest was an oversight for me, but I don't really use it.
iGoogle, which I do use, uses ajax to let you move the widgets around on the page, which is more of how I saw ajax. pretty fluffy stuff, but not really all that useful.
Now that I've had time to think about it, I realize that when you move stuff around it does have to interact with the server to save where you moved the widget to.
So I'm going to have to take another look at the whole subject, start thinking how I can make use of it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved