The first part works fine, this means the WKWebview object is able to call the java script function. The problem lies in the javascript code, I assume.
The javascript function, which is called, is supposed to read simply out of a text file in the app's bundle (fileName = "data.txt"). It looks like this:
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()
}
The output is always empty. Now I am sure that rawFile status reaches 4, I checked that. I have replaced the fileName with some make-believe non existent file and the rawfile status still reaches 4. So now I am not even sure whether the file has been found.
- Is there a way to determine whether the file was found?
- If it is found how can I read out of it?
I am not an experienced java script developer at all. So it might be some obvious problem. The javascript function I wrote with help of w3schools.com.
Thanks.