...

View Full Version : Resolved It Fails when I use 2 AJAX in one script...



auriaks
03-12-2010, 06:39 PM
Hi,

I am using two almost same scripts in the same page. Here is the all script:


<div id="header2">
asd
</div>
<!-- pradzia -->
<script language="javascript" type="text/javascript">
<!--
// Get the HTTP Object
function gethttpObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
// Change the value of the outputText field
function setOutput(){
if(httpObject2.readyState == 4){
document.getElementById('online').innerHTML = httpObject2.responseText;
}

}

// Implement business logic
function doWork(){
httpObject2 = gethttpObject();
if (httpObject2 != null) {
httpObject2.open("GET", "dalyviai.php", true);
httpObject2.send(null);
httpObject2.onreadystatechange = setOutput;
}
}
setInterval(doWork, 100);

var httpObject2 = null;

//-->
</script>
<div class="leftside">
<center>Pamokoje dalyvauja:<hr/>
<div id='online'>
</div></center>
</div>
<div id="page2">
<div id="pageinto1">
<script language="javascript" type="text/javascript">
// Get the HTTP Object
function gethttpObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
function setOutput(){
if(httpObject.readyState == 4){
document.getElementById('zinutes').innerHTML = httpObject.responseText;
}

}

// Implement business logic
function Work(){
httpObject = gethttpObject();
if (httpObject != null) {
httpObject.open("GET", "zinutes.php", true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput;
}
}
setInterval(Work, 1000);

var httpObject = null;
</script>
<center>Pamokos pokalbis<hr/></center>
<div id="zinutes">
</div>
</div>
<div id="pageinto2">
asd

</div>
</div>

So, the problem is that first ajax stopped working when I added second one.

Where is the problem?? maybe I can put the httml.object's together??

Thanks. :)

auriaks
03-12-2010, 07:21 PM
if you need more info - ask me... :)

auriaks
03-12-2010, 08:59 PM
Maybe the main problem is that I use
httpObject and
httpObject2 ??? :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum