我發現了很多關於如何閱讀位於www文件夾中的簡單文件的主題。他們中的大多數都很老,或者沒有給出如何使用它的例子。我試圖與科爾多瓦文件插件輕鬆閱讀與科爾多瓦www文件夾中的文件
cordova plugin add org.apache.cordova.file
,但我得到這個錯誤:
Error: Registry returned 404 for GET on https://registry.npmjs.org/org.apache.cordova.file
我試圖使用XMLHttpRequest的解決方案,但在模擬器中我沒有任何結果。這裏是我的代碼:
function xmlLoadFile()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.body.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.txt",true);
xmlhttp.send();
}
我有我的index.html的,所以我不明白爲什麼我仍然有一個空白頁時,我跑我的應用程序。
在此先感謝您的答案。
在這裏你去:https://www.raymondcamden.com/2014/07/15/Cordova-Sample-Reading-a-text-file/ – daserge