Flask Button run Python without refreshing page?

前端 未结 3 446
攒了一身酷
攒了一身酷 2020-12-31 16:42

I am just getting started into python and flask (for the raspberry pi). I want a web application that would execute some python code to pan and tilt a camera and display a v

3条回答
  •  旧巷少年郎
    2020-12-31 17:23

    I've got the same problem, and the answer is simple using ajax XmlHttpRequest:

    // send a request, but don't refresh page
    xhttp = new XMLHttpRequest();
    xhttp.open("GET", "your script action", true);
    xhttp.send();
    

    Here's a small example, calling current script with parameters "like", embedded in a function:

    function likeStuffs()
    {
        // send a request, but don't refresh page
        xhttp = new XMLHttpRequest();
        xhttp.open("GET", "?like", true);
        xhttp.send();
    }
    

提交回复
热议问题