3
所以我現在有一個JavaScript代碼,我在我的iPhone上運行它來提取其加速度計數據。我想要做的是將這些數據傳遞給我的Mac Book Pro,並使用Python腳本中的變量。變量每秒會多次更改,因此需要重複發送變量。我將不勝感激任何幫助,我可以得到。謝謝。在JavaScript中傳遞變量
<html>
<body>
<div id="content">
<h1>Accelerometer JavaScript Test</h1>
<ul>
<li>acceleration x: <span id="accelerationX"></span></li>
<li>acceleration y: <span id="accelerationY"></span></li>
<li>Motor Speed: <span id="speed"></span></li>
</ul>
</div>
<script type="text/javascript">
window.ondevicemotion = function(e){
var x = e.accelerationIncludingGravity.x;
var y = e.accelerationIncludingGravity.y;
var newx = x * 100
var newy = y * 100
var finalx = Math.round(x);
var finaly = Math.round(y);
document.getElementById("accelerationX").innerHTML = finalx
document.getElementById("accelerationY").innerHTML = finaly
speed = finalx * 10
document.getElementById("speed").innerHTML = speed
}
</script>
</body>
</html>
你是否已經想出了什麼?你知道你可以通過AJAX請求發送數據到另一端運行的服務器嗎? – slhck
謝謝你的迴應,不,我目前只是有JavaScript的變量,然後失去了如何讓他們到我的Mac。 – user3078477
每秒多次?看看套接字和網絡套接字。 – SamV