what methods can I use to have an HTML page contact the server in a persistent way without a new page load. What technologies can do this?
Is Ajax one of them?
persistent ways to keep an HTML conection to the server?
Started by
_*Ogflsnnbs_*
, Aug 12 2011 01:10 AM
2 replies to this topic
#1 _*Ogflsnnbs_*
Posted 12 August 2011 - 01:10 AM
#2
Posted 21 August 2011 - 12:13 PM
AJAX would be the simplest. I would recommend jQuery for your framework, it makes AJAX painless.
For example, to reload part of your site, it would be this simple.
index.php
When the content is clicked, it will trigger a call to pull the same page from the server again, and it will only load the contents of that container. I added a bit to have PHP echo the current time so you can prove it is pulling newer content seamlessly.
Another method, albeit obsolete and clunky, would be to use iframes. You could then make a button that refreshes the frame. I would not recommend this approach.
For example, to reload part of your site, it would be this simple.
index.php
<head> ... <script type="Javascript"> // Execute when the DOM is ready $(function(){ // Attach a click handler to our content element $('#content').click(function(){ // Load the content using an AJAX call $(this).load('index.php #content'); }); }); </script> ... </head> <body> ... <div id="content">This content was generated at <?php echo date(DATE_RFC822); ?>.</div> ... </body>
When the content is clicked, it will trigger a call to pull the same page from the server again, and it will only load the contents of that container. I added a bit to have PHP echo the current time so you can prove it is pulling newer content seamlessly.
Another method, albeit obsolete and clunky, would be to use iframes. You could then make a button that refreshes the frame. I would not recommend this approach.
#3
Posted 22 August 2011 - 02:59 PM
If this connection must be persistent like a chatbox, you might want to look into node.js It allows for a load of simultaneous open connections with only minimal server load.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users