Reputation: 81
Im looking to make a simple text-based game, and i was wondering how you set links for actions to be on the same page, so you wouldnt have to be redirected to a different page. So basically i just want everything in the game to be on one page, jus not all displayed at once.
Upvotes: 0
Views: 227
Reputation: 461
Basically, you need to refresh the page, but this time with new variables. If your page is called game.php, and you are updating the health:
$health = $_REQUEST['health'];
$health++;
echo "<meta http-equiv='refresh' content='game.php?health=$health'>";
This will constantly refresh the page, increasing the health by 1 every time.
Upvotes: 0
Reputation: 263577
If you are trying to avoid lots of different php files on the server for every page of the game, then pass a variable to php. E.g. the URL game.php?page=start
would set the variable $_REQUEST['page']
in your php script and you can make a condition based off of that.
If you are trying to avoid the page refreshing, then AJAX is the correct answer.
Upvotes: 1
Reputation: 4910
you can use jsonp.
what is jsonp :
JSONP is script tag injection, passing the response from the server in to a user specified function
see links:
also you can use jQuery.getJSON() to give data from jsonp
Upvotes: 0
Reputation: 4678
Use ajax to call other components of the page. It's the best way to manipulate a page without refresh.
Upvotes: 0