I am trying to validate the availability of a subdomain with the jQuery Validate Engine through a custom function. Validation appears to happen correctly but the alertText is not displayed if .ajax request returns 200. I have added Access-Control-Allow-Origin
headers and can see the request completing successfully in my logs.
What am I doing wrong?
Javascript Function:
function validateDomain(field, rules, i, options) {
var url = "https://" + field.val() + ".example.com/";
$.ajax(url,
{
statusCode: {
200: function() {
//alert('name exists already');
return options.allrules.validate2fields.alertText;
}
}
});
}
Form Field:
<label class="required" for="signup[subdomain]">Subdomain<span>*</span></label>
<span>https://</span>
<input id="signup[subdomain]" name="signup[subdomain]" class="field field validate[required,funcCall[validateDomain]]" type="text">
<span>.example.com</span>