Working on an issue with async commits
This commit is contained in:
@@ -1016,6 +1016,22 @@ export default class BaseAPI {
|
|||||||
if (!settings.sendBeaconCommit) {
|
if (!settings.sendBeaconCommit) {
|
||||||
const httpReq = new XMLHttpRequest();
|
const httpReq = new XMLHttpRequest();
|
||||||
httpReq.open('POST', url, settings.asyncCommit);
|
httpReq.open('POST', url, settings.asyncCommit);
|
||||||
|
if (settings.asyncCommit) {
|
||||||
|
httpReq.onload = function(e) {
|
||||||
|
if (typeof settings.responseHandler === 'function') {
|
||||||
|
result = settings.responseHandler(httpReq);
|
||||||
|
} else {
|
||||||
|
result = JSON.parse(httpReq.responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.result === true ||
|
||||||
|
result.result === global_constants.SCORM_TRUE) {
|
||||||
|
api.processListeners('CommitSuccess');
|
||||||
|
} else {
|
||||||
|
api.processListeners('CommitError');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (params instanceof Array) {
|
if (params instanceof Array) {
|
||||||
httpReq.setRequestHeader('Content-Type',
|
httpReq.setRequestHeader('Content-Type',
|
||||||
@@ -1027,11 +1043,18 @@ export default class BaseAPI {
|
|||||||
httpReq.send(JSON.stringify(params));
|
httpReq.send(JSON.stringify(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!settings.asyncCommit) {
|
||||||
if (typeof settings.responseHandler === 'function') {
|
if (typeof settings.responseHandler === 'function') {
|
||||||
result = settings.responseHandler(httpReq);
|
result = settings.responseHandler(httpReq);
|
||||||
} else {
|
} else {
|
||||||
result = JSON.parse(httpReq.responseText);
|
result = JSON.parse(httpReq.responseText);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
result = {};
|
||||||
|
result.result = global_constants.SCORM_TRUE;
|
||||||
|
result.errorCode = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return genericError;
|
return genericError;
|
||||||
|
|||||||
Reference in New Issue
Block a user