我使用POSTs將命令發送給arduino。我希望在按住按鈕的同時重複向上命令。這是我正在嘗試...如何在按住按鈕的同時獲取查詢按鈕以重複發帖?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="../templates/mainkibblynibblytemplate/css/kibbly-jquery.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
var timeout, clicker = $('#upbutton');
clicker.mousedown(function() {
timeout = setInterval(function() {
$.post('http://192.168.1.77:8888/', {
text: 'up'
});
}, 500);
return false;
});
$(document).mouseup(function() {
clearInterval(timeout);
return false;
});
</script>
</head>
<body>
<button id="upbutton">Test</button>
</body>
</html>
你有問題還是什麼? – asawyer
看起來它應該可以正常工作(儘管每半秒ajax請求可能會很多)。你看到了什麼? –
我已經編輯過以上所有的html。當按下按鈕時它不會發布。 – nonlinearmind