Skip to content

Instantly share code, notes, and snippets.

@sineld
Forked from TahaSh/ajax-validation-with-vue.js
Created October 11, 2016 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sineld/07a4edf7d8b4c40f750eba4173525eb9 to your computer and use it in GitHub Desktop.
Save sineld/07a4edf7d8b4c40f750eba4173525eb9 to your computer and use it in GitHub Desktop.
Ajax validation with VueJS
new Vue({
el: '#app',
data: {
formInputs: {},
formErrors: {}
},
methods: {
submitForm: function(e) {
var form = e.srcElement;
var action = form.action;
var csrfToken = form.querySelector('input[name="_token"]').value;
this.$http.post(action, this.formInputs, {
headers: {
'X-CSRF-TOKEN': csrfToken
}
})
.then(function() {
form.submit();
})
.catch(function (data, status, request) {
this.formErrors = data.data;
});
}
}
});
@sineld
Copy link
Author

sineld commented Oct 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment