Ok, this works fine:
$( "#myform" ).validate({
rules: {
email: {
remote: {
url: "/ajax/check-email.php",
mothod: "get",
dataFilter: function( response ) {
return response;
}
}
}
}
});
this configuration automatically made a GET to url:
/ajax/check-email.php?email=EMAIL-TO-CHECK
The problem is that I have this API to query:
/ajax/email/EMAIL-TO-CHECK/exists
So I have to create the url to be queried at runtime, but I can't do it in any way.
I tried to do this, using $.ajax() directly:
remote: function( ele ) {
var email = $(ele).val()
$.ajax({
url: "/ajax/email/"+ email + "/exists",
}).done(function( xhr ) {
return xhr
});
}
ut the validation does not fire.
I also tried to use a function for get "url", but "email" is empy. Like this:
var createUrl = function() {
var id = $("#myform input[name=email]").val(); //this is empty
return "/manager/ajax/pricelist/" + id + "/exists"
}
$( "#myform" ).validate({
rules: {
email: {
remote: {
url: createUrl(),
}
}
}
});
Any idea? Many many thanks.