phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


AJAX - Repetitive: Making Repetitive Asynchronous Request

Tag: AJAX, JavaScript, Repetitive Asynchronous Request   Category: PHP Application
post: 22 Mar 2008 read: 336


AJAX Repetitive Request Step By Step Tutorial - Part 1: Many application use repetitive request model such as chat room, real time application.

In this post, we try to create simple application that apply repetitive asynchronous request. The key is use JavaScript function:


setTimeout("function();", interval);

Example code like:


function handleXMLData()
{
  var xmlResponse = xmlHttp.responseXML;
  
   ...  
  var xmlData = xmlRoot.firstChild;
  var dataNodeName = xmlData.nodeName;
  if (dataNodeName != "random"){
    throw("4. Invalid XML Structure:\n " + xmlHttp.responseText);    
  }
 
 requestCounter++;  
 myDiv = document.getElementById("myDivElement"); 
 myDiv.innerHTML += "Request status: 4 (complete). <br />Request # " + requestCounter + ": "; 
 myDiv.innerHTML += xmlHttp.responseText;
 
 setTimeout("process();", interval = 1000);
 
}

Above, we always call process() function with interval 1000 milliseconds (that mean every 1 second).



Series this article:
AJAX - Repetitive: Making Repetitive Asynchronous Request
AJAX - Repetitive: Building Simple Application that Request Random Number
AJAX - Repetitive: Delaying Request

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting