Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Help 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);
}

https://github.com/josephyhu/Full-Stack-Foundations-Blog