• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SetTimeOut Function In Ajax

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all i am new to ajax but i know little so for my application i write setTimeinterval funtion for calling that function and executing ajax query for every 3 seconds but in middle it crashes and not showing proper data after 10 minutes , so i want to write SetTimeOut function and implemented inside ajax function and also implemented for one object
Example:-<script type="text/javascript">
function Ajax() {
var $http, $self = arguments.callee;

if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
$http = new ActiveXObject('Microsoft.XMLHTTP');
}
}

if ($http) {
$http.onreadystatechange = function() {
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function() {
$self();
}, 10000);
}
};
$http.open('GET', 'http://localhost:8080/IRADAR/content.jsp'
+ '?' + new Date().getTime(), true);
$http.send(null);
}

}
</script>
<script type="text/javascript">
setTimeout(function() {
Ajax();
}, 1000);
</script


but i am not getting how to implement for multiple object for multiple url calling how to implement, i write like but where and how i call setTimeout() it is not working properly

:-<script type="text/javascript">
function Ajax() {
var $http, $self = arguments.callee;
var $http1, $self = arguments.callee;
var $http2, $self = arguments.callee;


if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
$http1 = new XMLHttpRequest();
$http2 = new XMLHttpRequest();

} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
$http1 = new ActiveXObject('Msxml2.XMLHTTP');
$http2 = new ActiveXObject('Msxml2.XMLHTTP');

} catch (e) {
$http = new ActiveXObject('Microsoft.XMLHTTP');
$http1 = new ActiveXObject('Microsoft.XMLHTTP');
$http2 = new ActiveXObject('Microsoft.XMLHTTP');

}
}

if ($http) {
$http.onreadystatechange = function() {
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function() {
$self();
}, 10000);
}
};
$http.open('GET', 'http://localhost:8080/ssms.jsp'
+ '?' + new Date().getTime(), true);
$http.send(null);
}
if ($http1) {
$http.onreadystatechange = function() {
if (/4|^complete$/.test($http1.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http1.responseText;
setTimeout(function() {
$self();
}, 10000);
}
};
$http1.open('GET', 'http://localhost:8080/content.jsp'
+ '?' + new Date().getTime(), true);
$http1.send(null);
}

if ($http2) {
$http2.onreadystatechange = function() {
if (/4|^complete$/.test($http2.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http2.responseText;
setTimeout(function() {
$self();
}, 10000);
}
};
$http2.open('GET', 'http://localhost:8080/servit.jsp'
+ '?' + new Date().getTime(), true);
$http2.send(null);
}



}
</script>



Thanks in advance
S C P


 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is with all of the $ in the variable names? Your code is hard to read, please use code tags so it is formatted nicely.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic