posted 11 years ago
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