Error callback
A callback function invoked if the request fails.
$("form").async({
error: function(request) {
// Your code here
}
});
Trigger a validation
Valide the input content and throw an error if it's not an alphanumeric.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Success callback demo</title>
<link rel="stylesheet" href="http://127.0.0.1:4000/assets/css/demo.css">
</head>
<body>
<form action="/" method="post">
<input name="xs_username" placeholder="Username">
</form>
<script src="https://code.jquery.com/jquery-3.4.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/form-async/dist/form-async.min.js"></script>
<script>
function callback(request) {
var value = $(this).val(),
form = $(this).closest("form");
form.removeClass("error");
if (/[^a-zA-Z0-9]/.test(value)) {
form.addClass("error");
request.abort();
}
}
$("form").async({
before: callback
});
</script>
<body>
</html>