0

I want to transfer data from Javascript to mysql via flask, how to do it? In the below code, I calculate scores from the quiz and i want to post it in mysql database using flask

quiz.js


const lastQuestion = questions.length - 1;
let runningQuestion = 0;
let c1=0;
let c2=0;
let c3=0;
let c4=0;
let scorepos=0;
let scoreneg=0;

function storeAnswer(answer){
    if( answer == questions[runningQuestion].choice1){
        c1++;
    }else if( answer == questions[runningQuestion].choice2){
        c2++;
    }else if( answer == questions[runningQuestion].choice3){
        c3++;
    }else if( answer == questions[runningQuestion].choice4){
        c4++;
    }

    scorepos=c1+c2;
    scoreneg=c3+c4;
    console.log(c1);
    if(runningQuestion < lastQuestion){
        runningQuestion++;
        return renderQuestion();
    }else{
        graphRender(scorepos,scoreneg);
        scoreRender(c1,c2,c3,c4);
        renderAnalysis(scorepos,scoreneg,c1,c2,c3,c4)
        score1.innerHTML = "<p>C1:"+ c1 +"</p>";
        score2.innerHTML = "<p>C2:"+ c2 +"</p>";
        score3.innerHTML = "<p>C3:"+ c3 +"</p>";
        score4.innerHTML = "<p>C4:"+ c4 +"</p>";
    }
}

the calculation is done in js, i want to push it into mysql via flask. Node.js cannot be used so is there any other method?

3
  • use flask as API and pass using ajax request. Commented May 20, 2020 at 4:32
  • i am not familiar with api and ajax, can you help me out? Commented May 20, 2020 at 4:47
  • stackoverflow.com/questions/15537254/… see this can help you. Commented May 20, 2020 at 4:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.