Skip to content

Instantly share code, notes, and snippets.

Created November 7, 2012 23:22
Show Gist options
  • Select an option

  • Save anonymous/4035320 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/4035320 to your computer and use it in GitHub Desktop.
Demo of a simple (useless) PHP ajax thing based on prototype.js
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"
type="text/javascript"></script>
<script src="validator.js"
type="text/javascript"></script>
</head>
<body>
<form>
<label>Name
<input id="name" type="text" name="name" />
</label>
<label>ID Number
<input type="text" name="idnum" />
</label>
</form>
</body>
</html>
<?
$name = $_GET['name'];
print "Simon says".$name;
?>
function validate() {
$("name").observe("blur", youblurred);
}
function youblurred(){
// send a request to checking.php
new Ajax.Request("checking.php", {
parameters : {name: this.value},
onSuccess : successFunction,
method : "get"
});
}
function successFunction(dataPackage){
alert(dataPackage.responseText);
}
window.onload = validate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment