Can anyone please help me with this error?
I have been using jQuery along with vue.js. Below is the method I am having issue with... It is called by a post request. new_user
contains values received from the html form fields...
Values are being received nicely when I write it in console.
Problem comes when I try to use ajax method to store the data (this.$http.post()). I get the following error:
TypeError: Cannot read property 'replace' of undefined vue-resource.js:284
There were couple of links I went through.but i could take help from none... I might have made some silly mistakes because I used the above code from a perfectly running script. So if anyone can spot the mistake i would be grateful. Thanks... :)
Happy coding.
addUser : function(new_user){
// var instance = this;
console.log(this)
var new_user_input = this.new_user
console.log(new_user_input.name)//this works fine..
//problem comes right here
this.$http.post("clients/" , new_user_input).then((response) => {
alert("ok")
},(response) => {
alert("failed")
this.form_errors = response.data
// console.log("here should be the form errrors " + response.data.title)
});
}
If your using Laravel, make sure that you have in you template:
Good:
<script>
window.Laravel = <?php echo json_encode([
'csrfToken' => csrf_token(),
]); ?>
</script>
//OR
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
]) !!}
</script>
BAD:
<script>
window.Laravel = '<?php echo json_encode([
'csrfToken' => csrf_token(),
]); ?>'
</script>
//OR
<script>
window.Laravel = {{ json_encode([
'csrfToken' => csrf_token(),
]) }}
</script>