Java Reference
In-Depth Information
}
var parms = {
username: userValue
};
$.getJSON("ch14_formvalidator.php", parms).done(handleResponse);
} catch (ex) {
alert(ex.message);
}
}
function checkEmail(e) {
e.preventDefault();
var emailValue = $("#email").val();
try {
if (!emailValue) {
throw {
message: "Please enter an email address to check!"
};
}
var parms = {
email: emailValue
};
$.getJSON("ch14_formvalidator.php", parms).done(handleResponse);
} catch (ex) {
alert(ex.message);
}
}
function handleResponse(response) {
if (response.available) {
alert(response.searchTerm + " is available!");
} else {
alert("We're sorry, but " + response.searchTerm +
" is not available.");
}
}
$("#usernameAvailability").on("click", checkUsername);
$("#emailAvailability").on("click", checkEmail);
</script>
</body>
</html>
Remember that this example relies upon Ajax in order to work; so, be sure to save this page as
ch18 _ example2.html in your web server's root. In case you haven't set up a web server yet, see
Chapter 14 for more information.
You know how this example works, so we'll focus only on the highlighted code.
Search WWH ::




Custom Search