Can you call a laravel route in javascript?
I am trying to implement a front-end validation with jquery validate plugin. The reason that I am doing a front-end validation instead of the validation function provided by laravel is that I am using a bootstrap modal for my login form and I do not want the user to dismiss the form upon clicking the "submit" button.
Currently I am doing something like this:
$("#modal-form-login").validate({
errorClass: "error",
errorPlacement: function(error, element) {
error.insertAfter(element.parent("div"));
},
rules: {
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 4
}
},
messages: {
email: {
required: "メールアドレスが必要です",
email: "有効なメールアドレスを入力してください"
},
password: {
required: "パスワードが必要です",
minlength: jQuery.format("少なくとも {0} 文字")
}
},
submitHandler: function(form) {
$.ajax("http://mywebsite.com/login",{
dataType: 'json',
data: $('#modal-form-login').serialize(),
success: function(response) {
console.log("ok!");
}
});
}
});
I understand that the post-validation handling should be in submithandler, and I want to call my doLogin route (which is reachable via {{ URL: to("doLogin") }}
in blade), but can I achieve this in javascript?