/    Sign up×
Community /Pin to ProfileBookmark

Loading information without changing pages..

Hello. I’ve searched around a bit for this information and have found things somewhat close, but stll nothing helpful enough. I’m pretty new to php, and I believe I’ll need javascript for this too. I’m developing a game in php, and currently, when you battle a monster, or do any action, either it goes to another page, or reloads the current page with the information.

What I want to do, is have it so clicking a submit button…let’s say for fighting, instead of going to battle.php to load all of the battle information, it loads it in the index.php page, without the need to reload, loading instantly in the current frame. I’m pretty sure just a small demo will get me going. So instead of going in depth about the code, I’ll use a small example.

How would I have it so when I hit my submit button, it displays “You are fighting a $monstername!” in the current frame, without the whole page reloading or changing? Any help would be great. I really have no idea where to begin with this.

I just think it’d be much easier doing this, than to have to always change pages, and reloading chat because the page refreshes everytime. Thanks in advance for any help.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsJul 05.2005 — AJAX combines JS and PHP for a non-refreshing dynamic, PHP driven page. You might want to look into that.
Copy linkTweet thisAlerts:
@ShrineDesignsJul 05.2005 — you can use the JavaScript's XML HTTP request
Copy linkTweet thisAlerts:
@beginnerzJul 05.2005 — try this..........

index.php
[code=php]
<?php
session_start(); // start a new session.
if($_POST['Submit'] == 'Logon'){
include('../abc/abc1.php');
exit();
}else{
include('../abc/logout.php');
exit();
}
?>
[/code]


abc.php
[code=php]
<html>
<head><title>testing</title></head>
<body>
<form name="form1" method="post" action="index.php">
<input type="submit" name="Submit" value="Logon">
</body>
</html>
[/code]


abc1.php
[code=php]
<html>
<head>
<title>ABC TESTING 1</title>

</head>

<div align="center">
<table width="100%" height = "100%" align="center" border="0">
<tr>
<td><div align="center">Good Morning</div></td>
<td><input type="submit" name="Submit" value='submit' onclick="window.location.href = '/abc/abc3.php'"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="back" value='back' onclick="window.location.href = '/abc/abc.php'"></td>
</tr>
</table>
</div>
</body>
</html>
[/code]


abc2.php
[code=php]
<html>
<head>
<title></title>

</head>

<div align="center">
<table width="100%" height = "100%" align="center" border="0">
<tr>
<td><div align="center">Good Morning</div></td>
<td><input type="submit" name="Submit" value='submit' onclick="window.location.href = '/abc/abc3.php'"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="back" value='back' onclick="window.location.href = '/abc/abc.php'"></td>
</tr>
</table>
</div>
</body>
</html>
[/code]


abc3.php
[code=php]
<html>
<head>
<title></title>

</head>

<div align="center">
<table width="100%" height = "100%" align="center" border="0">
<tr>
<td><div align="center">Have a nice day!</div></td>
<td><input type="submit" name="Submit" value='submit' onclick="window.location.href = '/abc/abc2.php'"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="back" value='back' onclick="window.location.href = '/abc/abc.php'"></td>
</tr>
</table>
</div>
</body>
</html>
[/code]


logout.php
[code=php]
<?php
function redirect()

{

echo "<meta http-equiv="refresh" content="0;URL=abc.php">n";
exit();

}
redirect();
?>
[/code]
Copy linkTweet thisAlerts:
@beginnerzJul 05.2005 — sorry....forget to include

session.php
[code=php]
<?php

session_start();
session_unset();
session_destroy();
?>
[/code]


then add
[code=php]
<?php
include('../abc/session.php');
?>
[/code]


to the 1st line, inside abc.php
Copy linkTweet thisAlerts:
@helsleyJul 05.2005 — As ShrineDesigns mentioned, xmlHttpRequest is probably the best way to go. If you google it you will find ample information and probably helpful javascript/php classes to manage it for you (although you probably will want to write your own in the end). As usual, IE has their own way of instantiating the object, but other than that the syntax is the same across all browsers that support it (afaik).

If that won't work for your purposes (for whatever reason) you can also hide an iframe and make your requests target that frame, then grab the response out of the frame with js.
Copy linkTweet thisAlerts:
@UserFriendlyauthorJul 06.2005 — try this..........

index.php
[code=php]
<?php
session_start(); // start a new session.
if($_POST['Submit'] == 'Logon'){
include('../abc/abc1.php');
exit();
}else{
include('../abc/logout.php');
exit();
}
?>
[/code]


abc.php
[code=php]
<html>
<head><title>testing</title></head>
<body>
<form name="form1" method="post" action="index.php">
<input type="submit" name="Submit" value="Logon">
</body>
</html>
[/code]


abc1.php
[code=php]
<html>
<head>
<title>ABC TESTING 1</title>

</head>

<div align="center">
<table width="100%" height = "100%" align="center" border="0">
<tr>
<td><div align="center">Good Morning</div></td>
<td><input type="submit" name="Submit" value='submit' onclick="window.location.href = '/abc/abc3.php'"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="back" value='back' onclick="window.location.href = '/abc/abc.php'"></td>
</tr>
</table>
</div>
</body>
</html>
[/code]


abc2.php
[code=php]
<html>
<head>
<title></title>

</head>

<div align="center">
<table width="100%" height = "100%" align="center" border="0">
<tr>
<td><div align="center">Good Morning</div></td>
<td><input type="submit" name="Submit" value='submit' onclick="window.location.href = '/abc/abc3.php'"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="back" value='back' onclick="window.location.href = '/abc/abc.php'"></td>
</tr>
</table>
</div>
</body>
</html>
[/code]


abc3.php
[code=php]
<html>
<head>
<title></title>

</head>

<div align="center">
<table width="100%" height = "100%" align="center" border="0">
<tr>
<td><div align="center">Have a nice day!</div></td>
<td><input type="submit" name="Submit" value='submit' onclick="window.location.href = '/abc/abc2.php'"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="back" value='back' onclick="window.location.href = '/abc/abc.php'"></td>
</tr>
</table>
</div>
</body>
</html>
[/code]


logout.php
[code=php]
<?php
function redirect()

{

echo "<meta http-equiv="refresh" content="0;URL=abc.php">n";
exit();

}
redirect();
?>
[/code]
[/QUOTE]



Thanks beginnerz. That code seems to work well. I just have to spend some time recoding my pages to implement that into them. Might take awhile, but it'll be worth it and be much better than the iframes I have now which load new pages. I can do much more powerful things if I can get this working good.

Thanks again.

Cheers
×

Success!

Help @UserFriendly spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...