Previously, in one of our older examples for saving data, we had successfully used the following code in cordova UIWebview without any issues:
var filenameID;
function getFilenameID() {
$.ajax('/jquery/getdata', // request url
{
success: function (data, status, xhr) {
kp_requestKioskId_callback(data);
}
});
}
function kp_requestKioskId_callback(kioskId) {
filenameID = kioskId.split(" ").join("");
}
function saveData(fileName, data) {
getFilenameID();
kp_FileAPI_writeToFile(filenameID + ".xls", data, "writeFile_callback");
}
Upon migrating from UIWebview to WKWebview, the asynchronous nature of JavaScript execution in WKWebView has caused an issue where the 'getFilenameID' call is not completed before the 'kp_FileAPI_writeToFile' call, resulting in an undefined filename.
To resolve this issue, it was suggested to copy the 'kp_FileAPI_writeToFile' function inside the 'kp_requestKioskId_callback' function. However, since there are multiple similar functions in our application, making these changes would require significant modifications.
Is there a way to address or disable the asynchronous JavaScript execution to prevent extensive alterations to the application?