Forum Moderators: coopster
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?
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...
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]
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...]