« wróć
Javascript · 29.01.09 16:23 · 21.01.12 09:14
1. plik: testhtml.html (otwarty w przeglądarce z serwera www np. z lokalnego)
2. plik: testaja.php (na serwerze np. lokalnym)
<html>
<head>
<script type="text/javascript">
function ajax(id,url) {
var xmlHttp;
try {
xmlHttp = new XMLHttpRequest();
}
catch(e) {
try {
xmlHttp = new ActiveXObject("Msxml2.HMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Twoja przegladarka nie obsluguje AJAX\\'a!");
return false;
}
}
}
xmlHttp.onreadystatechange = function() {
if ( xmlHttp.readyState==4 ) {
document.getElementById(id).innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<div id="test"></div>
<button onClick="ajax(\\'test\\',\\'testaja.php\\')">pobierz</button>
</body>
</html>
2. plik: testaja.php (na serwerze np. lokalnym)
<?php
echo "Ala + kota";
?>