Sveiki, situācija sekojoša:
ir index.php fails: (atrasta kļūda labots)
<html>
<head>
<script src="ajax.js"></script>
</head><body onLoad="tcount()"><p><div id="txtHint"><b>Šeit bus informacija.</b></div></p>
<div id="t"></div>
</body>
</html>
ajax.js:
var xmlHttp
function showCustomer(str, a)
{
var url=a+"?sid=" + Math.random()
xmlHttp=GetXmlHttpObject(stateChanged)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}
function stateChanged()
{
if(xmlHttp.readyState == 1) done(1);
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject(handler) {
var objXmlHttp;
try
{
objXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
objXmlHttp.onreadystatechange=handler
}
catch(e)
{
try
{
objXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
objXmlHttp.onreadystatechange=handler
}
catch(f)
{
objXmlHttp=null;
}
}
if(! objXmlHttp&&typeof XMLHttpRequest!="undefined")
{
objXmlHttp=new XMLHttpRequest();
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
}
return objXmlHttp;
}
var c=0;
var t;
function tcount()
{
document.getElementById('t').innerHTML=c
c=c+1;
if(c>4) {c=1; showCustomer('', 'get.php');};
t=setTimeout("tcount()",1000);
}
get.php:
<img src="text.php?<? echo rand(); ?>" />
un text.php fails kurā tiek ar php ģenerēta bilde:
<?php
// create a 100*30 image
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left
imagestring($im, 5, 0, 0, rand(), $textcolor);
// output the image
header("Content-type: image/png");
imagepng($im);
//imagepng($im, "Bilde.png");
?>
Ko vēlos panākt ir, kad ajax pieprasa text.php faila bildi, tas parlūkā nomainās pret jauno text.php uzģenerēto bildi.
Viss notiek, tikai nepatīk tas ka parlūk refrešojas, tā itkā būtu nospiests F5 taustiņš. Ši ir maza bilde un tas varētu likties nieks, bet uz lielākām bildēm tas ir jūtams. Vai ir iespējams to novērst. Vai arī šis variants ir šķībs un tas jātaisa pavisam savādāk. Izstāstīt idejas līmenī, kā to novērts. Ar parastu tekstu viss notiek.
P.S. Butībā ko vēlos panākt ir ka bildes lapā dinamiski mainās, bez parlūka refrešošanās. Varbūt to labāk taisīt ar ActiveX, JAVA, etc. Bet tajos īpaši neorientējos. Kāds kas varbūt no tā kaut ko ir darījis varētu pastāstīt kā to panākt.