469,626 Members | 876 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Ajax loading

43
so i got this kind of ajax script

Expand|Select|Wrap|Line Numbers
  1. function browserio_tipas() {
  2.     var tipas;
  3.     if (window.ActiveXObject) {
  4.         tipas = new ActiveXObject("Microsoft.XMLHTTP");
  5.     } else if (window.XMLHttpRequest) {
  6.         tipas = new XMLHttpRequest();
  7.     }
  8.     return tipas;
  9. }
  10.  
  11. var ajax = makeObjectUSER();
  12.  
  13. function reload_users() {
  14.     ajax.open('GET', 'php.get.php?get=this');
  15.     ajax.onreadystatechange = function {
  16.         var grazina = ajax.responseText;
  17.         var divas = document.getElementById('divas');
  18.  
  19.         if(ajax.readyState == 4) {
  20.             divas.innerHTML = grazina;
  21.         } else {
  22.             divas.innerHTML = "Kraunasi...";
  23.         }
  24.     }
  25.     ajax.send('');
  26. }
  27.  
and is there any possible way to get how many % the script is loaded?
Oct 1 '07 #1
7 1261
acoder
16,027 Expert Mod 8TB
Do you mean a progress bar indicator?
Oct 1 '07 #2
dmjpro
2,476 2GB
so i got this kind of ajax script

Expand|Select|Wrap|Line Numbers
  1. function browserio_tipas() {
  2.     var tipas;
  3.     if (window.ActiveXObject) {
  4.         tipas = new ActiveXObject("Microsoft.XMLHTTP");
  5.     } else if (window.XMLHttpRequest) {
  6.         tipas = new XMLHttpRequest();
  7.     }
  8.     return tipas;
  9. }
  10.  
  11. var ajax = makeObjectUSER();
  12.  
  13. function reload_users() {
  14.     ajax.open('GET', 'php.get.php?get=this');
  15.     ajax.onreadystatechange = function {
  16.         var grazina = ajax.responseText;
  17.         var divas = document.getElementById('divas');
  18.  
  19.         if(ajax.readyState == 4) {
  20.             divas.innerHTML = grazina;
  21.         } else {
  22.             divas.innerHTML = "Kraunasi...";
  23.         }
  24.     }
  25.     ajax.send('');
  26. }
  27.  
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.

Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. .
  4. ajax.send(null); //here your ajax call is done, and it's should be asynchronous
  5. var new_ref = document.createElement("input");
  6. new_ref.setAttribute("type","text");
  7. document.body.appendChild(new_ref);
  8. //this is a text box to show how much the page loaded using ajax
  9. .
  10. .
  11. .
  12. function call_back()
  13. //this is your ajax handler
  14. {
  15.  new_ref.value = (ajax.readyState*25)+'% Loaded';
  16. }
  17.  
Here you can use a timer and make it more visual to users :-)
I think you got my point here.

Kind regards,
Dmjpro.
Oct 2 '07 #3
gits
5,390 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. function call_back()
  2. //this is your ajax handler
  3. {
  4.  new_ref.value = (ajax.readyState*25)+'% Loaded';
  5. }
  6.  
...
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
Oct 2 '07 #4
dmjpro
2,476 2GB
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.
Oct 2 '07 #5
tader
43
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
Oct 2 '07 #6
dmjpro
2,476 2GB
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.
Oct 2 '07 #7
acoder
16,027 Expert Mod 8TB
Then there are plenty of AJAX file upload progress bars. Search for "ajax upload progress bar" or something similar.
Oct 2 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by christopher.secord | last post: by
9 posts views Thread by Eric Wallstedt | last post: by
10 posts views Thread by shankwheat | last post: by
17 posts views Thread by Arjen | last post: by
11 posts views Thread by =?Utf-8?B?R2VyaGFyZA==?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.