I made a quiz with jQuery, very poorly coded. And now im recoding it using OOP. However, I have a problem storing JSON information into my model property.
var quizModel = {
currentQuestion: 0,
correctAnswers: 0,
init: function() {
"use strict";
$('.quiz').append('<div class="form"></div>');
$('.form').append('<form id="form"></form>');
quizView.addQuestion();
},
getJson: function() {
"use strict";
return JSON.parse($.ajax({
type: 'GET',
url: 'package.json',
dataType: 'json',
global: false,
async:false,
success: function(data) {
return data;
}
}).responseText);
},
answerDatabase: this.getJson()
};
I cant store the JSON object into the answerDatabase property. And I dont know why. When I wasnt using OOP I was able to do store the returned object into a variable and have access to that object across my javascript file. Anyone have a clue how to fix this? The console says (Uncaught TypeError: Cannot read property 'getJson' of undefined)