views:

645

answers:

2

I am creating a javascript API for SCORM 2004 4th Edition. For those who don't know about SCORM, basically it is an API standard that eLearning courses can use to communicate with an LMS (Learning Management System). Now the API has to have the following method:

  • Initialize(args)
  • GetValue(key)
  • SetValue(key, value)
  • Terminate(args)
  • Commit(args)
  • GetDiagnostic(args)
  • GetErrorString(args)
  • GetLastError()

Now Initialize has to be called before anything else, and Terminate must the last. GetValue/SetValue can be called anywhere in between there. What I am doing is in the Initialize method I am getting some JSON from a web service and storing that in the API (to be used when using the GetValue/SetValue methods later). The problem I am coming across is that the AJAX call via jQuery is asynchronous, so the Initialize method call could be done before the JSON is loaded. With that being the way it is, a call to GetValue after calling Initialize could cause unexpected issues b/c the JSON that GetValue uses isn't there yet. My question is this: What can I do to ensure that the JSON is loaded before the GetValue/SetValue methods are called? I know the simple answer is to make it synchronous, but that is not advised mostly, and it doesn't seem to want to do that for me. Here is my code regarding that:

function GetJSON(){
   var success = false;
   $.ajaxSetup({async:false}); //should make it synchronous
   $.getJSON("http://www.mydomain.com/webservices/scorm.asmx/SCORMInitialize?
              learnerID=34&jsoncallback=?",
             function(data){
                bind(data);
                success = true;
              }
   );   
   return success;
}

function bind(data){
   this.cmi = eval("(" + data.d + ")");
   $.ajaxSetup({async:true});  //should make it asynchronous again
}

Does anyone have any ideas? I would really appreciate it!

A: 

The way we approached this problem was to queue the CMI data in the API when the SCO is launched. We first navigate to a launch page that loads the CMI data into the API's queue, and then the laucnch page actually launches the SCO. When the SCO calls intialize, we just move the data into the CMI.

Ishmael
+2  A: 

Hi Dan,

You've articulated the problem well. After the SCO calls Initialize, the CMI data needs to be immediately available for the SCO to make subsequent GetValue calls. However, making synchronous AJAX calls isn't advised, if there is a hangup in the request, it can lock up the entire browser until the request returns or times out. The solution is to pre-load all of the required data before the SCO is loaded. In our SCORM Engine implementation, we preload all of the data (CMI and sequencing) when the player is launched and then use a background process to periodically commit dirty data as the learner progresses through the course. It can get a bit tricky to ensure that all data is properly persisted when dealing with the combinations of possible window launching and exit scenarios, but it's certainly possible. You will want to avoid any requests to the server from within a SCORM API call as SCOs will often flood the LMS with big batches of calls. Making server requests within those calls can seriously degrade the learner's experience and place a performance burden on the server.

Mike

Mike Rustici