The problem is that the AJAX call to your remote validator is asynchronous, which means that your answer comes back too late for Parsley, so it will always take a false result for verification.
While synchronous AJAX calls should be avoided , if you add the async: false option to your AJAX call, the code should work:
window.ParsleyValidator.addValidator('cardcode', function (value) { var valid = false; $.ajax({ url: '/data/checkout/cvvCheck.json', data: { cvv: value }, async: false, success: function(response) { if(response.valid === true) { return true; } else { return false; } } }); }, 32);
Here's the asynchronous method I found that worked for me - you need to load parsley.remote.min.js instead of parsley.min.js, then configure your own remote validator using this code:
window.Parsley.addAsyncValidator('cardcode', function (xhr) { var response = xhr.responseText; if (response.valid === true) { return true; } else { return false; } }, '/data/checkout/cvvCheck.json');
source share