Migration from iOS cordova UIwebview to wkwebview disable asynchronous javascript execution to support the existing application

In one of our older ‘Save Data’ examples, we had previously used the following and it was working fine without any issues in cordova UIWebview.

var filenameID;
function getFilenameID() {
$.ajax('/jquery/getdata', // request url
{
success: function (data, status, xhr) {// success callback function
kprequestKioskIdcallback(data);
}});
}
function kprequestKioskIdcallback(kioskId) {
filenameID = kioskId.split(" ").join("");
}
function saveData(fileName, data) {
getFilenameID();
kpFileAPIwriteToFile(filenameID + ".xls", data, "writeFilecallback");
}



After migrating from UIWebview to WKWebview, In WKWebView since JavaScript code is executed asynchronously, the ‘getFilenameID’ call is not completed before the ‘kp
FileAPIwriteToFile’ call is executed, resulting in an undefined filename.

Copying the kp
FileAPIwriteToFile function inside kprequestKioskId_callback will solve the issue.
But we have many similar kind of functions in our application.

Is there a way to solve or disable the asynchronous javascript execution to avoid major changes on the application.

Also,

I have never encountered this issue on the UIWebview, after migrating to WKWebview javascript code behaves asynchrously.

For e.g: We have 3 API calls which are dependent on one after the other for a single product.

Consider if we have 2 products, we are iterating the products in a loop and triggering 3 API for each product.
In WKWebview, it finishes the first thread and at last 2nd flow.
Migration from iOS cordova UIwebview to wkwebview disable asynchronous javascript execution to support the existing application
 
 
Q