• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

How To Create Ajax Progress Bar ...

In this tutorial you will know how to create an AJAX progress bar using javascript , In the following JavaScript source:

   1. var progress;   // progress element reference 
   2. var request;    // request object 
   3. var intervalID; // interval ID 
   4.  
   5. // button actions 
   6. function polling_start() {intervalID = window.setInterval( isend_request(),1500)} 
   7. function polling_stop()  {window.clearInterval(intervalID)} 
   8.  
   9. // define reference to the progress bar and create request object 
  10. window.onload = function (){ 
  11.   progress = document.getElementById(progress); 
  12.   request  = initXMLHttpClient(); 
  13. } 
  14.  
  15. // create an XMLHttpClient in a cross-browser manner 
  16. function initXMLHttpClient(){ 
  17.   var xmlhttp; 
  18.   try {xmlhttp=new XMLHttpRequest()} // Mozilla/Safari/IE7 (normal browsers) 
  19.   catch(e){                          // IE (?!) 
  20.     var success=false; 
  21.     var XMLHTTP_IDS=new Array(MSXML2.XMLHTTP.5.0,MSXML2.XMLHTTP.4.0, 
  22.                               MSXML2.XMLHTTP.3.0,MSXML2.XMLHTTP,Microsoft.XMLHTTP); 
  23.     for (var i=0; i<XMLHTTP_IDS.length && !success; i++) 
  24.       try {success=true; xmlhttp=new ActiveXObject(XMLHTTP_IDS[i])} catch(e){} 
  25.     if (!success) throw new Error(Unable to create XMLHttpRequest!); 
  26.   } 
  27.   return xmlhttp; 
  28. } 
  29.  
  30. // send request to the server 
  31. function send_request(){ 
  32.   request.open(GET,/my/ajax-progress-bar.php, true); // open asynchronus request 
  33.   request.onreadystatechange = request_handler;          // set request handler 
  34.   request.send(null);                                    // send request 
  35. } 
  36.  
  37. // request handler 
  38. function request_handler(){ 
  39.   if (request.readyState == 4){ // if state = 4 (the operation is completed) 
  40.     if (request.status == 200){ // and the HTTP status is OK 
  41.       // get progress from the XML node and set progress bar width and innerHTML 
  42.       var level=request.responseXML.getElementsByTagName(PROGRESS)[0].firstChild; 
  43.       progress.style.width = progress.innerHTML = level.nodeValue + \%; 
  44.     } 
  45.     else{ // if request status is different then 200 
  46.       progress.style.width = 100%; 
  47.       progress.innerHTML=Error: [+request.status+] +request.statusText; 
  48.     } 
  49.   } 
  50. } 

Here is the source of ajax-progress-bar.php:

   1. <?php 
   2. header(Content-type: text/xml); // define XML content type 
   3. print <?xml version="1.0"?>;    // print XML header 
   4. ?> 
   5. <DOCUMENT><PROGRESS><?= mktime() % 100 ?></PROGRESS></DOCUMENT> 

 Original Source:

AddThis Social Bookmark Button

Posted at 12:22:23 pm | Permalink | Posted in Javascript  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

e-messenger

MSN Web Messenger

eBuddy

ASP.NET Ajax CalendarExtender and Validation

AIM Express

Ajax Tools for ASP.NET Developers



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (176)
  • Ajax (112)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (21)
  • Chat (45)
  • ColdFusion (3)
  • CSS (84)
  • Email (23)
  • Facebook (84)
  • Flash (20)
  • Google (54)
  • Html (29)
  • Image (12)
  • International Calls & VOIP (7)
  • Java (58)
  • Javascript (280)
  • jQuery (200)
  • JSON (75)
  • Perl (2)
  • PHP (172)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (32)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (227)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (29)
  • YUI (13)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange