我不認爲你可以做到這一點與遠程驗證。解決問題的最佳方法是使用$.ajax
和addValidator
:
<input type="text" name="username" data-parsley-username />
<input type="text" name="location" id="location" />
<script>
window.ParsleyValidator
.addValidator('username', function (value, requirement) {
var response = false,
location = $("#location").val();
$.ajax({
url: "validation-url.htm",
data: {username: value, location: location},
dataType: 'json',
type: 'get',
async: false,
success: function(data) {
// if you send something from the server, you might want to
// do some verification here
response = true;
},
error: function() {
response = false;
}
});
return response;
}, 32)
.addMessage('en', 'username', 'Username is invalid.');
</script>