Skip to content

Commit 9f6cbda

Browse files
committed
fixed new post
1 parent 6c1fbff commit 9f6cbda

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

public/js/add-post.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
async function newFormHandler(event) {
22
event.preventDefault();
33

4+
45
const title = document.querySelector('input[name="title"]').value;
56
const post_content = document.querySelector('input[name="post_content"]').value;
67

78
const response = await fetch(`/api/posts`, {
8-
method: "POST",
9+
method: 'POST',
910
body: JSON.stringify({
1011
title,
11-
post_content,
12+
post_content
1213
}),
1314
headers: {
14-
"post_content-Type": "application/json",
15-
},
15+
'Content-Type': 'application/json'
16+
}
17+
1618
});
1719

1820
if (response.ok) {
19-
document.location.replace("/dashboard");
21+
document.location.replace('/dashboard');
22+
2023
} else {
2124
alert(response.statusText);
2225
}
23-
}
26+
};
2427

25-
document
26-
.querySelector(".new-post-form")
27-
.addEventListener("submit", newFormHandler);
28+
document.querySelector('#new-post-form').addEventListener('submit', newFormHandler);

0 commit comments

Comments
 (0)