mikeg542 Posted April 20, 2009 Share Posted April 20, 2009 Hi. My question is as follows: How does one go about making a program that when two players are logged onto the site and maybe there is a condition (like both have a $_GET['id'] number being the same), and one does something, it reloads the other's page. An example of this to clear it up is a chat program where when you type something and click enter, everyones chat reloads. I'm not asking for any extensive answers (though It'd be nice ), just a few words on what scripting language this is done in and what I should search for to learn it. Thanks a bunch! Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 You'll need to use ajax to continuously check for new posts. Or a continuously reloading iframe or something. Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 20, 2009 Share Posted April 20, 2009 And AJAX is JavaScript. This could also be done with Flash or Java (Java is not JavaScript) Quote Link to comment Share on other sites More sharing options...
mikeg542 Posted April 20, 2009 Author Share Posted April 20, 2009 I read something about using ajax/php that doesn't continually check the db for changes and only triggers an event if it is changed (to keep down on server load). I know some ajax, but no java/flash so I'd prefer that method. The main UI would be clicking on something and having it appear as an image on the main page for both users. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 Yeah, but how would the script know someting had changed if it doesn't continuously check? Quote Link to comment Share on other sites More sharing options...
mikeg542 Posted April 20, 2009 Author Share Posted April 20, 2009 good call, didn't think that through enough then, did I? Do any of you know if I could use jQuery to do this checking? I know how to use it to check the script page (just use .load()) but if there is a quick way to attach that to a timer event instead of a keyboard/click/mouse action... If there isn't a quick way, I'll try and find the harder one myself thanks again Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 I don't know how jQuery works as I've never needed to use it, I just code my own stuff, but you can set a function to run every so often with setInterval(); Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 20, 2009 Share Posted April 20, 2009 Well, hell, there was a tutorial in Better Software magazine from a few years ago that I read which is exactly what you need. It was an AJAX tutorial using a chat application as the example. It was title "The Many Layers of AJAX". I still have that issue on my bookcase, unfortunately I can't find the article available online - unless you bug a subscription to stickyminds.com to see the archives. But, the basic premise is that you would use AJAX to send/recieve the data from the Client and Server. The clinet would simply have a timed event to check the server to see if there are any updates (i.e. posts by other users) and a client invoked even (onclick) to send updates from the user. Quote Link to comment Share on other sites More sharing options...
mikeg542 Posted April 20, 2009 Author Share Posted April 20, 2009 So setInterval has been working right how I want it to, so thanks for that. I was just wondering if there is a reason this doesn't work in IE: <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script language="javascript" type="text/javascript"> var int=self.setInterval("clock()",1000) function clock() { $('.checky').load('load.php?id='+'<?php echo $row['id']?>'); } </script> For firefox it runs load.php every second, while in IE it runs it once then stops. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.