【问题标题】:I can't get the data of the responseText from android ajax with javascript我无法使用 javascript 从 android ajax 获取 responseText 的数据
【发布时间】: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


【解决方案1】:

我找到了运行它的简单方法。

wv1.loadDataWithBaseURL("http://yourWebSite/", htmlString, "text/html", "utf-8", null);

只需要将根文件夹从本地资产文件夹更改为网站...

-_-;;;

【讨论】:

    猜你喜欢
    • 2015-10-20
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 2021-11-13
    • 2013-07-27
    • 1970-01-01
    相关资源
    最近更新 更多