Jump to content


persistent ways to keep an HTML conection to the server?


  • Please log in to reply
2 replies to this topic

#1 _*Ogflsnnbs_*

_*Ogflsnnbs_*
  • Guests

Posted 12 August 2011 - 01:10 AM

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?

#2 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

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
<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 Wybe

Wybe

    Jedi In Training

  • Members
  • PipPip
  • 401 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:I have no interests

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