Validere ord på server
Jeg forsøger at lære noget AJAX og prøver nu at få sendt et enkelt ord til serveren for at kunnne validere på det. Men det virker ikke, og jeg har brug for din hjælp.her er skriptet:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
// Get the HTTP Object
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
// Change the value of the outputText field
function setOutput(){
if(httpObject.readyState == 4){
document.getElementById('outputText').value = httpObject.responseText;
}
}
function doWork(){
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("POST", "testord.php?inputText="
+document.getElementById('inputText').value, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput;
}
}
var httpObject = null;
//-->
</script>
<form name="testForm" id="guess" onSubmit="doWork();" method="post">
<input id="focus" type="text" name="inputText" size="22"><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
<div id="outputText">Tekst : </div>
</body>
</html>
------- end script -------
og her er testord.php
<?php
if (isset($_POST['inputText']))
echo strtoupper($_POST['inputText']);
?>
------- end script -------