In previous versions of CA Identity Portal, Ajax scripts have worked without issue, however, in 14.3 an error is returned.
Error : $ is undefined
The below is an example of a script used to pull data from a csv file to populate a drop-down list. This script worked in 14.1 but fails in 14.3
Sample Failing Script:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http:/iam-test.local/sigma/rest/resources/Files/DistributionList.csv",
dataType: "text",
success: function(allText) {
var allTextLines = allText.split(/\r\n|\n/);
var headers = allTextLines[0].split(',');
for (var i=1; i<allTextLines.length; i++) {
var data = allTextLines[i].split(',');
var dataName = data[0];
var dataValue = data[1];
prop.options.push({ name: dataName, value:dataValue });
}
console.log("Initializing list Completed");
}
});
});
Release : 14.3
Component : CA IDENTITY SUITE (VIRTUAL APPLIANCE)
AJAX scripts do work within 14.3 CP2 but there is no AJAX support for usage within the application.
To get AJAX scripts to work you must make sure that
1. The script is _NOT_ being invoked from Microsoft Internet Explorer (IE) browser as Microsoft has dropped the support of Ajax in IE.
2. The folder ('Files') with the specified CSV file exists under the 'resources' folder that hosts all the custom content.
3. Check whether the file is accessible directly in the browser by using the same URL (http://iam-test.local/sigma/rest/resources/Files/DistributionList.csv) that's being used in the script. If it's accessible via browser but not via script then we can further debug the script. If it's not accessible via browser then we need to correct the file path URL.
Below is an alternative approach, which has been tested and confirmed to work:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = handleStateChange;
xhr.open("GET", "https://iam-test.local/
xhr.send();
console.log("Request sent");
function handleStateChange() {
if (xhr.readyState == 4 &&
xhr.status >= 200 &&
xhr.status < 300) {
console.log("Got the response from backend.");
populateData(xhr.responseText)
}
}
function populateData(allText) {
var allTextLines = allText.split(/\r|/);
var headers = allTextLines[0].split(',');
for (var i=1; i<allTextLines.length; i++) {
var data = allTextLines[i].split(',');
var dataName = data[0];
var dataValue = data[1];
console.log("data =", data);
//prop.options.push({ name: dataName, value:dataValue });
}
console.log("Initializing list Completed");
}