-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting component data using AJAX #467
Comments
You need to make your x-data a function call <div x-show="subscribeVisible" x-data="component()">
<form id="subscribe" x-ref="form">
<input type="email" name="email" />
<button @click.prevent="submitForm($refs)">Subscribe</button>
</form>
<div x-show="success">Form submitted!</div>
</div>
<script>
function component () {
return {
subscribeVisible: false,
success: false,
submitForm() {
axios.post(this.$refs.form.action, new FormData(this.$refs.form))
.then(response => {
console.log(response.data);
return this.success === true
});
}
}
}
</script> |
Thanks so much. That did it. Here's the final solution:
|
👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm submitting a form with AJAX and having trouble setting my component's
success
value.Here's what I have so far:
The text was updated successfully, but these errors were encountered: