AJAX is a developer's dream, because you can:
- Update a web page without reloading the page
Request data from a server - after the page has loaded
Receive data from a server - after the page has loaded
Send data to a server - in the background
Porque não ?
Arquivo: gethint.prg
#!/usr/local/bin/hbrun
Function Main(...)
LOCAL cEOL := hb_eol() + hb_eol()
OutStd("Content-type: text/html" + cEOL )
OutStd("Maria" + hb_eol() )
RETURN ""
Arquivo: testeajax.html
<html>
<head>
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("POST", "cgi-bin/gethint.prg", true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
Para quem não está entendendo, usando AJAX é possÃvel abrir a comunicação com servidor e fazermos um VALID igual no Harbour/Clipper em um <input> a famoso GET-READ do harbour/clipper.
Saudações,
Itamar M. Lins Jr.