JavaScript in Captivate 9 Project not Executing
I have tried for hours to get some JavaScript inside of an Adobe Captivate 9 project (published as SWF and HTML5), deployed to a public web server, to execute. To aid in troubleshooting, I've wrapped various steps of the script with console.log("status");, and even those aren't executing.
A demo project file is located here: https://dl.dropboxusercontent.com/u/6787201/Test%20Interaction%20Data%20HTML5/Test-Interaction-Data.cptx
If you look at the JavaScript window, you'll notice there's a function call to sendInteractionData();
That's a custom function I wrote to fire off the data in various Captivate variables to a Google Spreadsheet. It is contained in the index.html page that I modify after publication. I've tested this function and it works when the values are explicitly defined and sendInteractionData() is called from a static web site... but when it's embedded in the Captivate JavaScript, no luck.
If you're interested, here's the code I insert to support the sendInteractionData() function:
// Setup section
// Paste the URL to the WEB SERVICE (obtained after running command PUBLISH > DEPLOY AS WEB APP) in the variable below!
var WebServiceURL = "mywebserviceurl";
// Do not edit below this line unless you intend to change the inner-workings of the script
// Declare some variables
var FirstName;
var LastName;
var Email;
var Attribute;
// Function to send the interaction data to the Google Spreadsheet. This function should be called by the Captivate Player AFTER setting the variables above.
function sendInteractionData() {
// Get and set the pertinent data from the Captivate Player
FirstName = window.cpAPIInterface.getVariableValue('cpFirstName');
LastName = window.cpAPIInterface.getVariableValue('cpLastName');
Email = window.cpAPIInterface.getVariableValue('cpEmail');
Attribute = window.cpAPIInterface.getVariableValue('cpAttribute');
// Send the data to the Google Sheet via AJAX call
request = $.ajax({
url: WebServiceURL,
type: "post",
data: "FirstName="+FirstName+"&LastName="+LastName+"&Email="+Email+"&Attribute="+Attribute
});
// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
// Log a message to the console
console.log("Wrote interaction data to Sheet: FirstName="+FirstName+"&LastName="+LastName+"&Email="+Email+"&Attribute="+Attribute+"// Message: Success!");
});
// Callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
// Log the error to the console
console.error(
"The interaction data could not be saved: FirstName="+FirstName+"&LastName="+LastName+"&Email="+Email+"&Attribute="+Attribute+"// The following error occurred: "+
textStatus, errorThrown
);
});
}
PS - reporting to a Google Spreadsheet really ought to be standard functionality by now...
Thanks for your help.
