【问题标题】:Phonegap Does httpRequest correctly in browser but not in phonePhonegap 在浏览器中正确执行 httpRequest 但在手机中不正确
【发布时间】:2017-06-14 05:29:19
【问题描述】:

我有下一个代码:

var xhttp = new XMLHttpRequest();

xhttp.open("GET", "http://www.youtube.com");

xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {

       document.getElementById('master').innerHTML = xhttp.responseText;

    }
};

xhttp.send();

我在 google 和 Facebook 上尝试了同样的方法,它在浏览器和手机中运行良好,但 youtube 仅在浏览器中运行 ¿ 发生了什么?

pd: browser = 桌面浏览器

pd: pd: 它进入 if 并执行 innerHTML 但在手机中 responseText 不返回任何内容

【问题讨论】:

    标签: cordova http ionic-framework get phonegap


    【解决方案1】:

    这可能是因为 http://www.youtube.com 重定向到 http://m.youtube.com 的用户代理可能取消了 www 的加载,只返回空响应。

    我已在我的 config.xml 中添加了此首选项以使用此桌面用户代理,我现在得到了响应。

    <preference name="OverrideUserAgent" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" />

    【讨论】:

    • 状态工作正常,它进入if并执行innerHTML,但在手机中responseText不返回任何内容
    • 谢谢!当我在虚拟设备中模拟它时可以工作,但在 Phonegap 应用程序中却不行:( ...至少它是这样的。:)
    • 是的,您的 config.xml 值不会影响 Phonegap Developer 应用程序,因为 Phonegap Developer 应用程序是一个 Phonegap 应用程序,它有自己的 config.xml github.com/phonegap/phonegap-app-developer/blob/master/…
    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 2021-06-21
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多