My page works fine if i navigate to the page http://localhost/abintegro/tests/sjt/1/index.html
however when I call the page via Ajax I get this error in inspect element console.
Error
Uncaught ReferenceError: Test is not defined
at HTMLDocument.<anonymous> (<anonymous>:6:21) at j (http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js?_=1476785885327:2:29948) at k (http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js?_=1476785885327:2:30262)
within index.html
if i comment out the function bellow the error is no more, however I need the function for the page to work.
My function
( function($, undefined) {
$(function() {
var test = new Test({
testName: "Situational Judgement Test 1",
dataURL : "./getresultshtml.php",
sendEmailURL: "./sendresultsbyemail.php",
contentFolder : "./",
solutionURL: "../../../content/f/id/21/",
userID: 0,
courseItemID: 42,
XMLFile: "exam.xml",
isStandalone: false
});
test.start();
});
}(jQuery));
the Ajax call in script.js
is as follows.
(once index.html
is called this way I get the error above)
The Call
$("#test3").click(function (event) {
$.post(
"tests/sjt/1/index.html",
function (data) {
$('.stage2').html(data);
}
);
});
//////////////Update//////////////////////
Test if used in a external file
function Test(settings){
var defaults = {
testName: "",
dataURL: "",
sendEmailURL: "",
contentFolder: "",
solutionURL: "",
downloadURL: "",
timesTaken: 0,
userID: 0,
courseItemID: 0,
XMLFile: "",
isStandalone: false
};
//merge defaults and settings
this.settings = $.extend({}, defaults, settings);
//module fields
this.testData = null;
//set up main test objects
this.eventHub = new EventHub();
this.Loader = new Loader(this.eventHub, this.settings);
}
Test.prototype.start = function(){
var context = this;
//load xml data and start test when data returns
this.eventHub.subscribeOnce(this, "loader/xml", function(data){
//get returned data object
context.testData = data;
context.settings.testType = data.testType;
//initialise the test runner
context.Runner = new Runner(context.eventHub, context.settings, context.testData);
context.UI = new UI(context.eventHub, context.settings);
context.Data = new Data(context.eventHub, context.settings);
//start preload of images and subscribe to loaded event
context.Loader.preloadImages(context.testData.questions);
//show intro screen
context.UI.prepareIntro(context.testData.introText);
});
this.Loader.loadXML(this.settings.XMLFile);
}