Skip to content

Instantly share code, notes, and snippets.

@TahaSh
Created January 16, 2016 14:36
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save TahaSh/99df18b049cbf2402c02 to your computer and use it in GitHub Desktop.
Save TahaSh/99df18b049cbf2402c02 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;
});
}
}
});
@sadeghian92
Copy link

sadeghian92 commented Apr 1, 2017

Hi, this code has a problem with Firefox. the form variable will be undefined for Firefox browser.
I think you should change line 11 to this:
var form = e.target || e.srcElement;

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