How to add Image Loader in AJAX ?

Discussion in 'Programming' started by naviarora2007, Mar 1, 2010.

  1. #1
    Hello,

    I want to use Image as a loader in this AJAX script instead of a text "Please wait..."
    I tried replacing the text with "<img src="link"/>", but it didn't worked.

    I am using this script: http://javascript.internet.com/ajax/ajax-navigation2.html
    And one more question, is this method of Ajax Navigation is Cross Browser Friendly?

    I would be grateful if someone can give me the solution.
    Thanks

    /* Ultimater's edited version of:
       http://jibbering.com/2002/4/httprequest.html
       to serve IE7 with XMLHttpRequest instead of ActiveX */
    
    var xmlhttp=false;
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
     	try {
     		 xmlhttp = new XMLHttpRequest();
     	} catch (e) {
     		 xmlhttp=false;
     	}
    }
    
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    if (!xmlhttp){
     try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }
    }
    @end @*/
    
    if (!xmlhttp && window.createRequest) {
    	try {
    		xmlhttp = window.createRequest();
    	} catch (e) {
    		xmlhttp=false;
    	}
    }
    
    /* Ultimater's edited version of:
       http://javascript.internet.com/ajax/ajax-navigation.html */
    
    var please_wait = "Please wait...";
    
    function open_url(url, targetId) {
      if(!xmlhttp)return false;
        var e=document.getElementById(targetId);if(!e)return false;
        if(please_wait)e.innerHTML = please_wait;
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = function() { response(url, e); }
        try{
          xmlhttp.send(null);
        }catch(l){
        while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
        e.appendChild(document.createTextNode("request failed"));
      }
    }
    
    function response(url, e) {
      if(xmlhttp.readyState != 4)return;
        var tmp= (xmlhttp.status == 200 || xmlhttp.status == 0) ? xmlhttp.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the following error code: " + xmlhttp.status+" "+xmlhttp.statusText;
        var d=document.createElement("div");
        d.innerHTML=tmp;
        setTimeout(function(){
          while(e.firstChild)e.removeChild(e.firstChild);//e.innerHTML="" the standard way
          e.appendChild(d);
        },10)
    }
    
    Code (markup):
     
    Last edited: Mar 1, 2010
    naviarora2007, Mar 1, 2010 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    You probably broke the code with double quotes?
    var please_wait = "<img src='http://www.domain.com/loading.gif' alt='Please wait...' />";
    Code (markup):
     
    Sky AK47, Mar 1, 2010 IP
  3. naviarora2007

    naviarora2007 Active Member

    Messages:
    163
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    No,

    I replaced
    var please_wait = "Please wait...";
    Code (markup):
    with
    var please_wait = "<img src='http://www.domain.com/loading.gif' alt='Please wait...' />";
    Code (markup):
    And it didn't worked.
     
    naviarora2007, Mar 2, 2010 IP
  4. naviarora2007

    naviarora2007 Active Member

    Messages:
    163
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Please help me....
     
    naviarora2007, Mar 8, 2010 IP
  5. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #5
    That's weird. Could you link me to the page you're testing it? I'd like to test something with firebug.
     
    Sky AK47, Mar 8, 2010 IP