...

View Full Version : Resolved Ajax append



primefalcon
11-17-2008, 06:36 AM
I have the following script that returns a simple php echo from a php script echo date("H:i:s"); to be precise, which is working fine.

what I want to know how to do though, is how to append date instead of replacing it

for example instead of just replacing

data

with

new data

how to make it add the new data to the old like old data, new data

and I'm not sure how to do this, can someone help please


here's the script


<html><head>
<title>Ajax test</title>
<script langauge="JavaScript">
var request = null;


function createRequest()
{
try
{
request = new XMLHttpRequest();
}
catch(trymicrosoft)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(othermicrosoft)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(failed)
{
request = null;
}
}


}








}</script>
</head><body>
<script langauge="JavaScript">


function updatePage()
{
if(request.readyState == 4)
{
var newData = request.responseText;
document.getElementById("pagedisplay").innerHTML = newData;


}

}

function main()
{
createRequest();
var serverurl = "http://localhost/ajaxtest/server.php";
request.open("GET", serverurl, true);
request.onreadystatechange = updatePage;
request.send(null);
setTimeout('main()', 1);

}

setTimeout('main()', 250);

</script>
<div id="pagedisplay"></div>



</body></html>

primefalcon
11-17-2008, 06:56 AM
Nvm I worked it out myself


<html><head>
<title>Ajax test</title>
<script langauge="JavaScript">
var request = null;


function createRequest()
{
try
{
request = new XMLHttpRequest();
}
catch(trymicrosoft)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(othermicrosoft)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(failed)
{
request = null;
}
}


}








}</script>
</head><body>
<script langauge="JavaScript">


function updatePage()
{
if(request.readyState == 4)
{
var newData = request.responseText;
var olddata = document.getElementById("pagedisplay").innerHTML;
var Display = olddata + "<br />" +newData;
document.getElementById("pagedisplay").innerHTML = Display;


}

}

function main()
{
createRequest();
var serverurl = "http://localhost/ajaxtest/server.php";
request.open("GET", serverurl, true);
request.onreadystatechange = updatePage;
request.send(null);
setTimeout('main()', 500);

}

setTimeout('main()', 250);

</script>
<div id="pagedisplay"></div>



</body></html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum