Ajax请求没有';第二次不行,为什么


Ajax request doesn't work second time, why?

我的PHP文件运行电机,Forward.PHP使它们朝一个方向运行,Backward.PHP则朝相反的方向运行。出于某种原因,当我打开页面,例如按下向上按钮时,它工作正常,电机向前运行。然后一切都错了。如果我再次向前按压,大约10秒钟内什么都没发生,然后突然电机变得很奇怪,开始抖动。

如果我打开index.html并按下forward,那么我刷新页面并再次按下forward就可以了。。。但如果我刷新页面,然后按下向下按钮,电机就会再次出现异常,无法正常工作。

然而,如果我从终端运行电机代码,无论我运行多少次,它们都可以按任何顺序正常工作。我知道电机代码很好,我不认为这是pi的问题,但网站。。。如果我在网站搞砸了之后从终端运行电机,那么即使在终端中,它们也会停止正常运行。。

php文件使用系统:("python/var/www/html/Forward.py"),这已经在终端中进行了单独的测试,并且运行良好

如有任何帮助,将不胜感激

这是我的代码:

<html>
<head>
<title>RC car Control Website</title>
<link href="Website.css" rel="stylesheet">
</head>
<body>
<header>Website Controlled RC Car</header>
<button type="button" id="up"> <img src="images/up" width="50" height="50">        </button><br>
<button type="button" id="down"> <img src="images/down" width="50"     height="50"/></button><br>
<button type="button" id="right"> <img src="images/right" width="50" height="50"/></button><br>
<button type="button" id="left"> <img src="images/left" width="50" height="50"/></button><br>
<script type ="text/javascript"     src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type ="text/javascript">
$(document).ready(function () {
    var xhr;
        $("#up").mousedown(function() {
    $.ajax ({
                method: "GET",
                url: "http://192.168.1.94/Forward.php",
 });
 });
     $("#up").mouseup(function() {  
    $.ajax ({
            method: "GET",
                url: "http://192.168.1.94/MotorStop.php",});
                });    
});
</script>
<script type ="text/javascript"         src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type ="text/javascript">
 $(document).ready(function () {
    var xhr;
        $("#down").mousedown(function() {
    $.ajax ({
                method: "GET",
                url: "http://192.168.1.94/Backward.php",
     });
     });
     $("#up").mouseup(function() {  
    $.ajax ({
                method: "GET",
                url: "http://192.168.1.94/MotorStop.php",});
                });    
 });
</script>
</body>
</html>

我认为mouseup函数,你不能重复,你只需要有一个mouseup功能

$("#up").mouseup(function() {  
    $.ajax ({
                method: "GET",
                url: "http://192.168.1.94/MotorStop.php"
            });
});