my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes SetTimeOut Function In Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "SetTimeOut Function In Ajax" Watch "SetTimeOut Function In Ajax" New topic
Author

SetTimeOut Function In Ajax

sadhu charan
Greenhorn

Joined: Nov 27, 2012
Posts: 18
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


Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SetTimeOut Function In Ajax