Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

javascript - Send data to Hardware and go to another webpage?

My goal is to use a photon and by click on a button some data is sent to the photon via the cloud. However, at the same time I would like to go to another page as well. The problem is that when I try to press the button, it doesnt even go to the other page. Im not sure yet if the data is even being sent (haven't tested), but it should go to another page. Any help is much appreciated.

    <!DOCTYPE html>
<html>

<body>

<input id="Memory Button" type="button" value="Memory Game" onclick="return myFunction1("setGame"),myFunction2()"/>

<script language="javascript" type="text/javascript">



function myFunction1(objButton)
{
    var deviceID = "1f0026001847353236343033";
    var accessToken = "edc90d3d0f4048681a946f75a7bbe221ad7e1110";
    var baseURL = "https://api.particle.io/v1/devices/";

    varname=objButton;
    requestURL= baseURL + deviceID + "/" + varName + "/?access_token=" + accessToken;
    $.post( requestURL, { params: varName , access_token: accessToken });
}

function myFunction2()
{
    window.location.href = 'http://twin-cities.umn.edu/';
}

</script>


</body>

</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

onclick should be onclick="myFunction1('setGame');myFunction2()" like

<input id="Memory Button" type="button" value="Memory Game" onclick="myFunction1('setGame');myFunction2()"/>

total

<!DOCTYPE html>
<html>

<body>

<input id="Memory Button" type="button" value="Memory Game" onclick="myFunction1('setGame');myFunction2()"/>

<script language="javascript" type="text/javascript">



function myFunction1(objButton)
{
    var deviceID = "1f0026001847353236343033";
    var accessToken = "edc90d3d0f4048681a946f75a7bbe221ad7e1110";
    var baseURL = "https://api.particle.io/v1/devices/";

    varname=objButton;
    requestURL= baseURL + deviceID + "/" + varName + "/?access_token=" + accessToken;
    $.post( requestURL, { params: varName , access_token: accessToken });
}

function myFunction2()
{
    window.location.href = 'http://twin-cities.umn.edu/';
}

</script>


</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...