在Javascript部分,您會看到計算得分的方式以及它如何在網站上顯示,但我希望得到的分數插入我的燒瓶應用程序所以我可以將分數插入我的MySql數據庫。對不起,我的英語不好。插入一個Javascript變量到燒瓶應用程序中,然後將它插入到Mysql數據庫中
的Javascript:
// Computes score and returns a paragraph element to be displayed
function displayScore() {
var score = $('<p class="quizvraag">', {id: 'question'});
var numCorrect = 0;
for (var i = 0; i < selections.length; i++) {
if (selections[i] === questions[i].correctAnswer) {
numCorrect++;
}
}
score.append('You got ' + numCorrect + ' questions out of ' +
questions.length + ' right!!!');
return score;
}`
瓶:
@app.route('/quiz')
def quiz():
startquiz()
DbLayer = DbClass()
vragen = DbLayer.getQuizVraag()
list_vraag = [vragen]
print(vragen)
return render_template('quiztestjs.html', vraag=vragen, list_vraag=list_vraag)
MySQL查詢:
def setDataToDatabase(self, Score1):
# Query met parameters
sqlQuery = "INSERT INTO tbl_score (Score1) VALUES ('{param1}')"
sqlCommand = sqlQuery.format(param1=Score1)
self.__cursor.execute(sqlCommand)
self.__connection.commit()
self.__cursor.close()
查找AJAX +燒瓶。 – cwallenpoole