I’m not going to make this a tutorial on AJAX – you may want to do some background reading on it before we go much further. Or you can just take what I say on trust … it’s up to you.
An AJAX request is a JavaScript object. The way that the object is created depends on the browser that’s being used (sigh!) since Microsoft implements it using an ActiveX object, and other browsers have a native implementation. So I need to test for the browser when I create the request object.
Fortunately, there’s a lot of code out there that will save me the effort of developing it myself – see, for example, this excellent tutorial provided by IBM. Here’s my version.
function createRequest() {
// this is the object that we're going to (try to) create
var request;
// does the browser have native support for
// the XMLHttpRequest object
try {
request = new XMLHttpRequest();
}
// it failed so it's likely to be Internet Explorer which
// uses a different way to do this
catch (tryIE) {
// try to see if it's a newer version of Internet Explorer
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
// that didn't work so ...
catch (tryOlderIE) {
// maybe it's an older version of Internet Explorer
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
// even that didn't work (sigh)
catch (failed) {
alert("Error creating XMLHttpRequest");
}
}
}
return request;
}
I’ll add this to the api.html file that I created earlier so that it can be used by the SCORM RTE API functions.
Next step … using the AJAX request in the SCORM API functions.
Pingback: Desarrollando un LMS(con soporte de SCORM) « Jorge Dieguez Blog
Pingback: Desarrollando un LMS(con soporte de SCORM)