Hello everybody,
I wrote a file using AJAX this is the code I wrote:
File.js

var http = createRequestObject();
function createRequestObject(){
    var request_;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        request_ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        request_ = new XMLHttpRequest();
    }
    return request_;
}
function getInfo(){
    http.open('get', 'GtCht.php');
    http.onreadystatechange = handleInfo;
    http.send(null);
}
function handleInfo(){
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('ChtPlc').innerHTML= [B]document.getElementById('ChtPlc').innerHTML + response;[/B]
    }
}

I binded that file with a function in JavaScript:
<script language="javascript">
function GetINF(){
window.setTimeout(getInfo(),1000)
}
</script>
So when this file selects an animated image from the MySQL database it refreshes the image automaticially each 1 second, however I want this image to stay moving until its final frame.
Could you help please? :-/

Recommended Answers

All 3 Replies

My comments are in the code:

var frame=0;
var interval=null;
var http = createRequestObject();
function createRequestObject(){
    var request_=null;

    //not necessary
    //var browser = navigator.appName;
	if(window.XMLHttpRequest)
	{
	request_ = new XMLHttpRequest();
	}
    else if(window.ActiveXObject){
        request_ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return request_;
}
function getInfo(){
	if( http )
	{
		//first parameter MUST BE UPPERCASE
		http.open('GET', 'GtCht.php');
		http.onreadystatechange = handleInfo;
		http.send(null);
		++frame;
		if(frame < 24 )
		{
			clearInterval(interval);
		}
    }
    else
    {
    	alert("Your browser does not support AJAX.");
    }
}
function handleInfo(){
	//must make sure you optained the resource successfully
    if(http.readyState == 4 && http.status==200){
        var response = http.responseText;
        document.getElementById('ChtPlc').innerHTML= document.getElementById('ChtPlc').innerHTML + response;
    }
}

function GetINF(){
 interval = setInterval(getInfo(),1000)
}

Thanks but that does not help...
I want to keep the images (.GIF) moving until it completes.
However my file does not do that...
the page auto-refreshes...
Can you solve it?

Can you link us to a sample page so we can find out what *exactly* are you trying to do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.