我目前正在使用MeteorJS和CrossWalk开发智能手表(摩托罗拉MOTO 360第一代)app原型,该原型必须与远程服务器连接以获取信息并根据其改变其可视化。为此,我使用XMLHttpRequest
。当我在计算机上运行Meteor应用程序时,它都可以在PC上运行。它与我的服务器连接,并获取信息。
但是在使用Android Wear的智能手表上,如果我记录每个readyStateChange
并写下这个" log"在应用文档中,我得到的不仅仅是readyState 4
和status 0
。连接未打开,我没有收到标题,也没有下载(否则,readyState 1
,2
和3
也会出现。
之前我遇到过这个问题,我必须更改mobile-config.js
才能允许跨域访问。我添加了以下代码:
App.accessRule('*');
此外,我创建了一个manifest.json
文件,其中我添加了以下代码(我模糊了实际的服务器域):
{
"name": "Watch Proto",
"start_url": "watch-proto.html",
"xwalk_hosts": [
"https://nameofmyserverhe.re/*",
"http://nameofmyserverhe.re/*"
]
}
所有这一切似乎没有任何区别;我仍然无法连接外部服务器,这与我在PC上运行应用程序时不同。如何在Android Wear上获取XMLHttpRequest
我的应用程序?
我已经发布了以下代码:
<head>
<title>watch-proto</title>
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1,width=device.width, height=device.height, user-scalable=no" data-name="viewport">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="manifest" href="/manifest.json" />
</head>
<body class='green'>
{{> watchNotification }}
</body>
<template name='watchNotification'>
<ul id="hour-marks">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<ul id="marks">
<li style="transform:rotate(18deg)" class='warning'></li>
<li style="transform:rotate(60deg)" class='unknown'></li>
<li style="transform:rotate(270deg)" class='hint'></li>
</ul>
<div id="arms">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
<div id='notification'>
<div class='content'>
<div class='overflower'>
{{{innerHTML}}}
</div>
</div>
<svg viewBox="0 0 369.9804688 369.9804688" id="kpiPerformance">
<circle stroke-width="25" cx="184.9902344" cy="184.9902344" r="173" id="circle" fill="rgba(0,0,0,0)"></circle>
</svg>
</div>
</template>
App.accessRule('*');
{
"name": "Watch Proto",
"start_url": "watch-proto.html",
"xwalk_hosts": [
"https://nameofmyserverhe.re/*",
"http://nameofmyserverhe.re/*"
]
}
if (Meteor.isClient) {
Meteor.startup(function () {
var pad = "https://nameofmyserverhe.re/path/to/file.php";
var xhrTimeout, errorCounter = 0;
Session.setDefault("innerHTML",infoBase[0]);
function xhr(pad, Session,infoBase){
// repeat the function in the callback, after 1000ms
var xhr = new XMLHttpRequest();
xhr.open("GET",pad,true,"user","password");
var xhrLog = "";
xhr.onreadystatechange = function(ev){
xhrLog += xhr.readyState+" | "+xhr.responseText+" ("+xhr.status+")<br />";
if(xhr.readyState == 4){
var cl = document.body.classList;
if(!cl.contains('notification')){
cl.add('notification');
}
Session.set("innerHTML","<div style='color:#FFF;text-align:center;padding-top:25px;'>"+xhrLog+"</div>");
}
}
xhr.send();
}
xhr(pad,Session,infoBase);
});
Template.watchNotification.helpers({
"innerHTML":function(){
return Session.get("innerHTML");
}
});
}