The initial part is functioning correctly, indicating that the WKWebview object can successfully call the javascript function. The issue seems to be within the javascript code itself.
The purpose of the javascript function being called is to simply read from a text file located in the app's bundle (fileName = "data.txt"). Here is how it looks:
function readTextFile(fileName)
{
var rawFile = new XMLHttpRequest();
rawFile.onreadystatechange = function()
{
if(rawFile.status == 4)
{
document.getElementById("demo").innerHTML = this.responseText;
}
}
rawFile.open("GET",file,true)
rawFile.send()
}
However, the output is consistently empty. Despite confirming that the rawFile status does reach 4, I am now uncertain as to whether the file is actually being found. Even after substituting the fileName with a fictional non-existent file, the rawFile status still reaches 4. This uncertainty leaves me questioning if the file has been located at all.
- Is there a method to verify whether the file was indeed located?
- If the file is present, how can its contents be successfully read?
I openly admit my lack of expertise in javascript development. Therefore, the root of the problem may be something rather obvious. The creation of the javascript function was done with support from w3schools.com.
Your assistance is greatly appreciated.