Error: Object doesn't support this property or method
The value of variable 'result' is 404 (numeric). The call to split this number by line-break fails when the return code is the single number indicating file not found. This can be fixed by casting result to a string, leaving the errorCode variable undefined.
results = String(result).split("\n");
Note: The cause of this issue is the failure of the POST HTTP request, causing page redirection to return the response code 404 (even though an actual page is reached). I suspect this may be caused by session variable expiry, since the referenced /mod/scorm/datamodel.php file does exist. The error is more common when the server is under load, typically indicated by a longer time taking to return from the DoRequest() method.
The return value of StoreData() function appears not to be used - which can result in the silent loss of student results!