我有下一个代码:
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();
我尝试使用谷歌和Facebook,它在浏览器和手机上运行良好,但youtube仅适用于浏览器¿发生了什么?
pd:browser =桌面浏览器
pd:pd:输入if并执行innerHTML,但在手机中,responseText不返回任何内容
答案 0 :(得分: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" />