0

I'm using the template below to create a simple web-form to control the lights in my house using the Particle Photon IoT board.

I would like the form to just accept a button-push but not move forward to another page, which it currently does, giving me a response from the device.

I'd like to print the response from the device on the page but not move away from the controls, I'm sure there must be either a basic HTML or more complicated Javascript answer to this, I just don't know it.

Are you able to help at all?

Thanks!

Tim

**UPDATE: Thanks for pointing out the other post. However I have no control over the response from the server (it's not my server) so the solution you found doesn't really help... unless it does and I just don't understand how.

/* Paste the code between the dashes below into a .txt file and save it as an .html file. Replace your-device-ID-goes-here with your actual device ID and your-access-token-goes-here with your actual access token.

---------------------------
<!-- Replace your-device-ID-goes-here with your actual device ID
and replace your-access-token-goes-here with your actual access token-->
<!DOCTYPE>
<html>
  <body>
  <center>
  <br>
  <br>
  <br>
  <form action="https://api.particle.io/v1/devices/987654321/led?access_token=123456789" method="POST">
    Tell your device what to do!<br>
    <br>
    <input type="radio" name="args" value="1">Turn the LED to 1.
    <br>
    <input type="radio" name="args" value="2">Turn the LED to 2.
    <br>
    <input type="radio" name="args" value="3">Turn the LED to 3.
    <br>
    <input type="radio" name="args" value="4">Turn the LED to 4.
    <br><br>
    <input type="submit" value="Do it!">
  </form>
  </center>
  </body>
</html>
---------------------------
*/
  • have a google for ajax sounds like what you're after. Also you shouldn't put anything above the doctype like that – Pete May 05 '17 at 12:16
  • Thanks @Pete I did have a look around for Ajax but I really don't understand how it works. I don't suppose you can point me at a decent example/tutorial can you? – Tim Tiernan May 05 '17 at 12:28
  • http://thisinterestsme.com/simple-ajax-request-example-jquery-php/ and http://html.net/tutorials/javascript/lesson21.php maybe should help you. – Abhijeet Das May 05 '17 at 12:38
  • Hey Tim - I know the pains of learning Ajax! I've written it up into a code pen for you: https://codepen.io/benjih111/pen/OmxZjN?editors=1111 – Benjamin May 05 '17 at 12:43
  • This is Axios (the thing sending the Ajax request) https://github.com/mzabriskie/axios - hopefully it helps – Benjamin May 05 '17 at 12:44
  • You could also use Particle API JS library that does the Ajax for you: https://jsfiddle.net/suda/8jq1z8f0/ – suda Jun 22 '17 at 16:11

0 Answers0