Npr. na brzinu:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function getRequestObject() {
var req = null;
if (typeof XMLHttpRequest != "undefined")
req = new XMLHttpRequest();
if (!req && typeof ActiveXObject != "undefined") {
try {
req=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
req=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {
try {
req=new ActiveXObject("Msxml2.XMLHTTP.4.0");
}
catch (e3) {
req=null;
}
}
}
}
if(!req && window.createRequest)
req = window.createRequest();
return req;
}
function processRequest() {
var req;
var p = document.form1.text1.value;
uri = 'ajax.php?test=' + encodeURIComponent(p);
req = getRequestObject();
req.open('GET', uri, true);
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if (req.status==200) {
if (req.responseText) {
processResponse(req.responseText);
}
}
delete req;
}
req.send(null);
delete req;
return true;
}
function processResponse(text) {
document.getElementById('status').innerHTML = text;
}
</script>
</head>
<body>
<form name="form1" method="post" action="submit.php">
<fieldset>
<p>
<label for="">Text 1</label>
<input type="text" name="text1" value="" />
<input type="button" value="ajax get" onclick="processRequest();" />
</p>
<p>
<input type="submit" name="submit" value="submit" />
</p>
</fieldset>
</form>
<div id="status"></div>
</body>
</html>
a u ajax.php npr.
Code:
<?php
if(!empty($_GET['test']) AND trim($_GET['test']) != '')
echo 'Ovo je poslato PHP-u: <strong>' . $_GET['test'] . '</strong>';
else
echo 'Greska: Nista nije poslato. <br />Potrebno je uneti podatke u polje "Text 1"';
?>
[Ovu poruku je menjao Br@nkoR dana 19.04.2011. u 22:02 GMT+1]
Banned - Not available