我正在尝试用它自己的网络服务器建立一个气象站。到目前为止页面的代码是这样的:
<!DOCTYPE html>
<html>
<head>
<title>WS-100 Server</title>
<script>
function UpdatePage()
{
var request = new XMLHttpRequest();
request.onreadystatechange = function()
{
if(this.readyState == 4) {
if(this.status == 200) {
if(this.responseText != null) {
document.getElementById("currentTemp").innerHTML = this.responseText;
}
}
}
}
request.open("GET","ajax_update_temp",true);
request.send(null);
request= new XMLHttpRequest();
request.onreadystatechange = function()
{
if(this.readyState == 4) {
if(this.status == 200) {
if(this.responseText != null) {
document.getElementById("currentDatetime").innerHTML = this.responseText;
}
}
}
}
request.open("GET","ajax_update_time",true);
request.send(null);
setTimeout("UpdatePage()", 10000);
}
</script>
</head>
<body onload="UpdatePage()">
<h1>WS-100 Weather Station</h1>
<div id="currentDatetime">
<p> </p>
</div>
<div id="currentTemp">
<p> </p>
</div>
</body>
</html>
它在桌面浏览器上运行良好,但在移动浏览器上只显示日期时间,而在我的旧三星 galaxy 上,没有任何显示。我考虑过将这两个查询合并为一个,但最终我想至少执行两个请求:一个针对当前时间和温度,另一个用于下载和处理历史测量值的 txt 文件。
这只是浏览器的限制还是应该有办法解决它?
最佳答案
尝试运行 $('document').ready(function());
因为在移动 webview 中,桌面浏览器的某些功能受到限制以保持其性能。所以有时候你需要写 $('document').ready(function());
而不是 onload()
关于javascript - 第二个 ajax 请求不适用于移动浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28360854/