Jump to content
MakeWebGames

Update information without refreshing


Recommended Posts

Hello,

I am here in need of help as I need advice or help from someone. I want to make the information of the members to update without them refreshing their browsers. Such as their crystals, money, level, energy bar etc.

[ATTACH=CONFIG]2118[/ATTACH]

I've seen in a game where the general information update without refreshing however, the bars of the images do not move correctly.

Sorry about my English or if I do not make sense.

 

Good day, and thanks for reading! ~ Guardian

847774684_ScreenShot2015-06-25at02_04_00.png.2e71076eb14d10436ba6d8c5b262cf15.png

Link to comment
Share on other sites

Well for that you should look into Ajax. Now I am going to give my advice on why you probably don't need it. Judging by where you posted this and the screen shot you provided, it looks like you are using MCC. Now, unless you have modified your code to dynamically load your content inside a container of its own your pages refresh with every click of a link or button(for the most part, excluding some modules). If that's the case, why would you need this? If a user is online, chances are they are playing and clicking around etc. when they click your header will also refresh updating everything to be current.

Now let's say your dead set on achieving the Ajax header. You are just adding additional server load by adding requests to hit queries at a certain interval in turn sucking up your bandwith. I mean chances are it's not a ton of bandwith but with several users it can add up. You can set a timeout checking to see if the page has focus or if it's blurred and trigger an event to help save some of them resources of the player is not actually viewing the game. But again why? When they come back again they will probably go ahead and click a link anyways, thus, setting their stats to their current state client side.

I dont want it to sound like I'm hating on th idea because I currently adopted this same thing with the help from [MENTION=64684]Dayo[/MENTION] and implemented desktop notifications but it only runs if the document/window has focus and this is for an ecommerce type setting so if we are away doing something else the events won't fire.

Link to comment
Share on other sites

You could possibly even use a node.js server with sockets so that you don't need to do ajax polling granted this a bit more work but would eliminate most of the strain on your server.

If this is not possible (ie your on shared hosting or dont want to learn it) you can use ajax polling, but as you are using mccodes you will need to make a php script that only puts a php array in JSON format then use JQuerys $.ajax with a setInterval()

Link to comment
Share on other sites

Thank you all for the replies! Appreciate that you have taken time and replied back. As Kyle was saying there is no point about it. I agree as I made my whole website ajax (http://makewebgames.io/showthread.php/45495-Ajaxify-jQuery-your-Entire-MC-Code-Game-Any-MC-Code-Version)

And thanks for the advice about Ajax, jQuery and JSON I am reasearching something new now and will be starting to learn the new web languages. Also what would be the best web languages to start of with? I have started with HTML and PHP fairly good with it. However, not an expert.

:)

Thanks again!

Link to comment
Share on other sites

Well if that's the case then what you need to do is just create an array of stats that you want like:

$stats = array('energy' => $energy,'will' => $will);// just do the same with all the stats you want
//next  encode it using json
$encodedStats = json_encode($stats);
echo $encodedStats:";

That will output something the stats in json format

Next you can use an Ajax call something like:

$.ajax({
   url: "thefile.php",
   dataType: "JSON",
   success: function(data) {
       //here is where you can load your elements with the data received by your file
   }
});

When I get on my computer tomorrow I can maybe upload the script that Dayo helped me out with to get it and also with desktop notifications

Edited by KyleMassacre
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...