Vue Communicates with the Internet Chapter 14
this.response = xhr.response
} else {
this.response = 'Error: ' + xhr.status
}
}
}
xhr.send(JSON.stringify({
title: this.title,
body: this.body,
userId: this.userId
}))
}
}
To see the actual response of the server, we will add the response variable to our status:
data: {
userId: 1,
title: '',
body: '',
response: '...'
}
After the form in our HTML, add the following:
<h3>Response from the server</h3>
<pre>{{response}}</pre>
When you launch your page, you should be able to interact with your server. When you
write a post, the server will echo the post and answer with the post ID: