1) This AJAX function gets skipped if I try to run in debug mode in Chrome 2) When I just run it normally, the AJAX works and I get arrays of length 64 outputted to console. However after the AJAX call, the same arrays become empty and the length becomes 0
I even tried using $(document).ready
instead of $("#nextQ").click(function(){
$("#nextQ").click(function(){
var Quotes = [];
var ID = [];
var Tag = [];
var seen = [];
//Get quotes from JSON file
$.ajax({
url: '../facts.json',
datatype: 'json',
type: 'get',
success: function(data){
console.log(data);
console.log("successfully imported the JSON file");
console.log(data.length); //Used to return 64
totalQ = data.length;
for (i = 0; i < totalQ; i++){
ID[i] = data[i][0];
Tag[i] = data[i][1];
Quotes[i] = data[i][2];
seen[i] = data[i][3];
}
console.log(Quotes.length);
}
});
//-----------------------
//This is where it all breaks down..the following totalQ is empty
//
var Quote = new String;
var qnumber = 0;
var totalQ //The total number of available quotes to choose from
var Qrem //Remaining unseen quotes
var lock = new Boolean; //This will be true if the quote is already seen
var CurrentImage = String;
totalQ = Quotes.length - 1; //This length is returning 0 and totalQ = -1
console.log("TotalQ = " + totalQ);
ChooseQuote(0,totalQ);