When trying to do a post from a component in my ember app to my express api I am receiving
SyntaxError: Unexpected token V in JSON at position 0
When checking what response I'm receiving in the network inspector on chrome I see
ValidationError: body: Path `body` is required., title: Path `title` is required. undefined
The blogpost.title and .body both return the correct values but the blogpost gives me
adapterError: SyntaxError: Unexpected token V in JSON at position 0 at parse
EmberApp/App/Components/create-new-post/Component.js
export default Component.extend({
blogpost: null,
router: inject('-routing'),
actions: {
save: function (blogpost) {
console.log(blogpost.title);
console.log(blogpost.title);
console.log(blogpost);
blogpost.save()
.then(
(value) => {
Ember.Logger.info(value);
this.get('router').transitionTo('index')
}
)
.catch(
(err) => {
Ember.Logger.info('failure to save');
console.log(err);
}
)
}
}
});
EmberApp/App/Components/create-new-post/template.hbs
<form >
<p>
</p>
<p>
</p>
<p>
<button class="btn btn-primary btn-block" type="submit" value="Save">Publish</button>
</p>
</form>
EmberApp/App/routes/createpost.js
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return this.store.createRecord('blogpost');
}
});
EmberApp/App/templates/createpost.hbs
<div class="container">
<div class="col-sm-12 pull-left">
</div>
</div>
I have confirmed that the api route for post is working with postman so I'm not sure what the issue is with ember.
Aucun commentaire:
Enregistrer un commentaire