Pagina HTML:
codice:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio</title>
<script type="text/javascript">
function readPHPResponse () {
var oResponse = JSON.parse(this.responseText);
if (oResponse.change) {
document.getElementById("immagine").src = oResponse.change;
}
}
function checkForImage () {
var oReq = new XMLHttpRequest();
oReq.onload = readPHPResponse;
oReq.open("get", "cambiaimmagine.php", true);
oReq.send();
}
</script>
</head>
<body>
[img]tuaImmagine.jpg[/img]</p>
</body>
</html>
La pagina PHP restituirà:
codice:
{ "change": "immagineCheVuoiTu.jpg" }
oppure
codice:
{ "change": false }