Created
January 16, 2016 14:36
-
-
Save TahaSh/99df18b049cbf2402c02 to your computer and use it in GitHub Desktop.
Ajax validation with VueJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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;