I have a very simple code, I'm using PHP VueJs and axios for Ajax requests
I have a button that sends data by ajax to a php file per post but it does not recognize post data, that I infer from this error:
Notice: Undefined index: email in /opt/lampp/htdocs/projects/winecommunity/php/index.php on line 2
HTML
<button @click="sendEmail">Enviar </button>
<p> {{{res}}} </p>
<script src="js/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="js/index.js"></script>
THE php
echo $_POST['email'];
and the js
new Vue({
el: 'body',
data: {
email:'[email protected]',
res:'tu email'
},
methods: {
sendEmail: function (){
var vm = this;
axios.post('php/index.php', {
email:vm.email,
})
.then(function (response) {
vm.res = response.data
})
.catch(function (error) {
console.log(error);
});
}
}
})
Any idea what I need for php to return the email to me?