public/js/questions.js
// add question with fetch post method
add question with fetch post method
add question with fetch post method
function addQuestion(event) {
    event.preventDefault()
    let quizId = this.getAttribute('data-id')
    let question = document.getElementById('question').value
    let answer = document.getElementById('answer').value
    let choice_a = document.getElementById('choice_a').value
    let choice_b = document.getElementById('choice_b').value
    let choice_c = document.getElementById('choice_c').value
    console.log(question)
    fetch(`/questions/add/${quizId}`, {
        method: 'POST',
        body: JSON.stringify({ question, answer, choice_a, choice_b, choice_c }),
        headers: {
            'Content-Type': 'application/json',
        },
    })
        .then(res => {
            console.log(res)
            window.location.reload()
        })
        .catch(err => console.log(err))
}
function addQuestion ( event ) { event . preventDefault ( ) let quizId = this . getAttribute ( 'data-id' ) let question = document . getElementById ( 'question' ) . value let answer = document . getElementById ( 'answer' ) . value let choice_a = document . getElementById ( 'choice_a' ) . value let choice_b = document . getElementById ( 'choice_b' ) . value let choice_c = document . getElementById ( 'choice_c' ) . value console . log ( question ) fetch ( ` ${ quizId } ` , { method : 'POST' , body : JSON . stringify ( { question , answer , choice_a , choice_b , choice_c } ) , headers : { 'Content-Type' : 'application/json' , } , } ) . then ( res => { console . log ( res ) window . location . reload ( ) } ) . catch ( err => console . log ( err ) ) }
add question with fetch post method
add question with fetch post method