Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Yhu
PHP Development Techdegree Graduate 48,637 PointsHelp with My Full Stack Foundations Track's Final Project (PROJECT COMPLETED)
Update: I've completed the project.
I need help with posting/updating posts in my blog (final project for the Full Stack Foundations track). I'm trying to get updating posts to work first.
update.html:
<!DOCTYPE html>
<html>
<head>
<title>Full Stack Foundations Blog</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<header>
<nav>
<a href='index.html'>Home</a>
</nav>
</header>
<div id="post">
<form method="post">
<label for="title">Title<span style="color:red;">*</span></label><br>
<input type="text" v-model="title" required><br><br>
<label for="content">Content<span style="color:red;">*</span></label><br>
<textarea v-model="content" required></textarea><br><br>
<button type="button" onclick="update(title, content)">Update</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="js/post.js"></script>
<script src="js/routes.js"></script>
</body>
</html>
routes.js:
function updatePost(id, title, content) {
const path = `http://localhost:8000/api/v1/posts/${id}`;
axios.put(path, {title: title, content: content})
.then(response => response.data)
.then(() => window.location.replace(`post.html?id=${id}`))
alert('Post updated');
}
function update(title, content) {
updatePost(id, title, content);
}
function deletePost(id) {
const path = `http://localhost:8000/api/v1/posts/${id}`;
confirm('Confirm delete');
axios.delete(path)
.then(response => response.data)
.then(() => window.location.replace('index.html'))
alert('Post deleted');
}
function del() {
deletePost(id);
}