【发布时间】:2016-03-24 17:10:58
【问题描述】:
我使用 loadDataWithBaseURL 在 Android 上打开 webView。
wv1.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "utf-8", null);
在那个 htmlString 中。我尝试使用 responseText 打开 ajax,但它不起作用。 htmlString 中的 javascript 如下...
function fucMiniDic(strKey){
var tarDiv = document.getElementById('divMiniDic');
tarDiv.style['visibility'] = 'visible';
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
tarDiv.innerText = xhttp.responseText;
}
};
xhttp.open('GET', 'http://myWebSite/page.aspx?strkey='+strKey, true);
xhttp.send();
}
通过大量的谷歌搜索......我稍微了解'http://myWebSite'正在考虑android资产中的一个文件夹,而不是像万维网域。因为我使用 loadDataWithBaseURL 来打开 webview。
所以...我的问题是如何从万维网的 ajax 中获取 responseText,从 Android 中的资产文件夹中转义?
当我在 PC 上测试 ajax 代码时,运行良好。所以,我认为我的代码中没有语法错误。唯一的问题是 Android 上的 ajax 方法。
【问题讨论】:
-
您是否在配置中添加了
<access origin="*" />? -
plz,我需要更多信息。你的意思是phoneGap的config.xml?
-
参考这个:stackoverflow.com/questions/19003025/… 和许多类似的答案。
标签: javascript android ajax webview responsetext