File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
async function newFormHandler ( event ) {
2
2
event . preventDefault ( ) ;
3
3
4
+
4
5
const title = document . querySelector ( 'input[name="title"]' ) . value ;
5
6
const post_content = document . querySelector ( 'input[name="post_content"]' ) . value ;
6
7
7
8
const response = await fetch ( `/api/posts` , {
8
- method : " POST" ,
9
+ method : ' POST' ,
9
10
body : JSON . stringify ( {
10
11
title,
11
- post_content,
12
+ post_content
12
13
} ) ,
13
14
headers : {
14
- "post_content-Type" : "application/json" ,
15
- } ,
15
+ 'Content-Type' : 'application/json'
16
+ }
17
+
16
18
} ) ;
17
19
18
20
if ( response . ok ) {
19
- document . location . replace ( "/dashboard" ) ;
21
+ document . location . replace ( '/dashboard' ) ;
22
+
20
23
} else {
21
24
alert ( response . statusText ) ;
22
25
}
23
- }
26
+ } ;
24
27
25
- document
26
- . querySelector ( ".new-post-form" )
27
- . addEventListener ( "submit" , newFormHandler ) ;
28
+ document . querySelector ( '#new-post-form' ) . addEventListener ( 'submit' , newFormHandler ) ;
You can’t perform that action at this time.
0 commit comments