public/javascript/create-post.js
// write js to enable user to create posts
write js to enable user to create posts
write js to enable user to create posts
async function newFormHandler(event) {
    event.preventDefault();
    const title = document.querySelector('input[name="post-title"]').value;
    const post_content = document.querySelector('input[name="post-content"]').value;
    const response = await fetch(`/api/posts`, {
      method: 'POST',
      body: JSON.stringify({
        title,
        post_content
      }),
      headers: {
        'Content-Type': 'application/json'
      }
    });
    if (response.ok) {
      document.location.replace('/dashboard');
    } else {
      alert(response.statusText);
    }
  }
async function newFormHandler ( event ) { event . preventDefault ( ) ; const title = document . querySelector ( 'input[name="post-title"]' ) . value ; const post_content = document . querySelector ( 'input[name="post-content"]' ) . value ; const response = await fetch ( ` ` , { method : 'POST' , body : JSON . stringify ( { title , post_content } ) , headers : { 'Content-Type' : 'application/json' } } ) ; if ( response . ok ) { document . location . replace ( '/dashboard' ) ; } else { alert ( response . statusText ) ; } }
write js to enable user to create posts
write js to enable user to create posts