There is an endpoint available for submitting data using a POST request,
http://localhost:3000/entry
The required keys are fname, lname, age
By sending a POST request to the specified endpoint, a new entry will be created.
Currently, I am attempting to submit a form using VueJS. However, when trying to call the API within the form, the data is not getting submitted. I have verified the network calls and it shows that no data is being sent to the endpoint.
HTML Code:-
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.4/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.1.16/vue-resource.min.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<div id="vueApp">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h3>
Dashboard
</h3>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="fname">First Name</label>
<input type="text" class="form-control" value="" v-model="fname" />
</div>
<div class="form-group">
<label for="lname">Last Name</label>
<input type="text" class="form-control" value="" v-model="lname" />
</div>
<div class="form-group">
<label for="age">Age</label>
<input type="text" class="form-control" value="" v-model="age" />
</div>
</div>
<div class="col-sm-12">
<a href="#" class="btn btn-success" @click="submitEntry">Submit</a>
<span v-if="ajaxRequest">Please Wait ...</span>
</div>
</div>
<div> </div>
<div class="row" v-if="debug">
<div class="col-sm-12">
<pre>{{ $data | json }}</pre>
</div>
</div>
<!-- Table Start -->
<div class="row">
<table style="width:100%">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<tr>
<td>{{fname}}</td>
<td>{{lname}}</td>
<td>{{age}}</td>
</tr>
</table>
</div>
<!-- Table END -->
</div>
</div>
Javascript Code (script.js) :-
Vue.http.options.emulateJSON = true;
new Vue({
el: '#vueApp',
data: {
debug: true,
fname: '',
lname: '',
age: '',
ajaxRequest: false,
postResults: []
},
methods: {
submitEntry: function() {
this.ajaxRequest = true;
this.$http.post('http://localhost:3000/entry', {
fname: this.fname,
lname: this.lname,
age: this.age
}, function (data, status, request) {
this.postResults = data;
this.ajaxRequest = false;
});
}}
});
CSS Styling (style.css) :-
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}