简体   繁体   中英

How do you set links for the same page?

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.

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. Eg 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.

Use ajax to call other components of the page. It's the best way to manipulate a page without refresh.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM