Ajax loading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tader
    New Member
    • Sep 2007
    • 43

    Ajax loading

    so i got this kind of ajax script

    Code:
    function browserio_tipas() {
        var tipas;
        if (window.ActiveXObject) {
            tipas = new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) {
            tipas = new XMLHttpRequest();
        }
        return tipas;
    }
    
    var ajax = makeObjectUSER();
    
    function reload_users() {
        ajax.open('GET', 'php.get.php?get=this');
        ajax.onreadystatechange = function {
            var grazina = ajax.responseText;
            var divas = document.getElementById('divas');
    
            if(ajax.readyState == 4) {
                divas.innerHTML = grazina;
            } else {
                divas.innerHTML = "Kraunasi...";
            }
        }
        ajax.send('');
    }
    and is there any possible way to get how many % the script is loaded?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Do you mean a progress bar indicator?

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by tader
      so i got this kind of ajax script

      Code:
      function browserio_tipas() {
          var tipas;
          if (window.ActiveXObject) {
              tipas = new ActiveXObject("Microsoft.XMLHTTP");
          } else if (window.XMLHttpRequest) {
              tipas = new XMLHttpRequest();
          }
          return tipas;
      }
      
      var ajax = makeObjectUSER();
      
      function reload_users() {
          ajax.open('GET', 'php.get.php?get=this');
          ajax.onreadystatechange = function {
              var grazina = ajax.responseText;
              var divas = document.getElementById('divas');
      
              if(ajax.readyState == 4) {
                  divas.innerHTML = grazina;
              } else {
                  divas.innerHTML = "Kraunasi...";
              }
          }
          ajax.send('');
      }
      and is there any possible way to get how many % the script is loaded?
      You can do that using JavaScript.
      Have a look on it.
      As the Ajax call is behind-scene then there is not effect on Browser-Progress Bar.
      So you have to make your own visual effects.

      [code=javascript]
      .
      .
      .
      ajax.send(null) ; //here your ajax call is done, and it's should be asynchronous
      var new_ref = document.create Element("input" );
      new_ref.setAttr ibute("type","t ext");
      document.body.a ppendChild(new_ ref);
      //this is a text box to show how much the page loaded using ajax
      .
      .
      .
      function call_back()
      //this is your ajax handler
      {
      new_ref.value = (ajax.readyStat e*25)+'% Loaded';
      }
      [/code]

      Here you can use a timer and make it more visual to users :-)
      I think you got my point here.

      Kind regards,
      Dmjpro.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        Originally posted by dmjpro
        [code=javascript]
        function call_back()
        //this is your ajax handler
        {
        new_ref.value = (ajax.readyStat e*25)+'% Loaded';
        }
        [/code]
        ...
        one note in case you test it with different browsers and wonder why it works different too: not all browsers notify all readyStates (IE = 1-4; Opera8.5 = 3-4; Safari2.0.1 = 2-4; ...) so that the code will work but the effects are different ...

        kind regards

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by gits
          one note in case you test it with different browsers and wonder why it works different too: not all browsers notify all readyStates (IE = 1-4; Opera8.5 = 3-4; Safari2.0.1 = 2-4; ...) so that the code will work but the effects are different ...

          kind regards
          Yes :-)
          That's right.
          I just came to know it.
          Anyway thanks for your kind information.

          Kind regards,
          Dmjpro.

          Comment

          • tader
            New Member
            • Sep 2007
            • 43

            #6
            hm.... it shows only 25% 50% 75% i need it to show all per cents because im planing to create an upload form with it and upload big files so i rely need it to show
            all per cents

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by tader
              hm.... it shows only 25% 50% 75% i need it to show all per cents because im planing to create an upload form with it and upload big files so i rely need it to show
              all per cents
              No way !
              The only way is to rely on the Ready States of Ajax.
              Then you can further break up those states into sub-parts and set a Timer for visual effects.
              You got my point :-)

              Kind regards,
              Dmjpro.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Then there are plenty of AJAX file upload progress bars. Search for "ajax upload progress bar" or something similar.

                Comment

                Working...