1

I am working on the basics of learning how to control Raspberry Pi GPIO from a web server. However, I am running into a problem. Here is my current set up.

index.html, the main webpage

<html>
<head>
    <meta charset="utf-8" />
    <title>Blink</title>
</head>
<body style="background-color: white;">

<!-- Button to call blink -->
<button type="button" onclick="blink()">blink</button>

<!-- javascript -->
    <script src="script.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

</body>

script.js (where the I call php.php through ajax)

function blink() {
$.ajax({
    url:"php.php", //the page containing php script
    type: "POST", //request type
 });
}

php.php, where I control the GPIO

<?php 
exec("gpio -1 write 11 1");
sleep(1);
exec("gpio -1 write 11 0");
?>

Currently, the code works as far as controlling the GPIO works. I have an LED hooked up and it lights up and everything. However, I am receiving a dialog box in Chrome after every time the php file is done running. The dialog box is blank, and I assume it has something to do with either Ajax or Jquery returning an empty value. This is where my knowledge is lacking, and I would appreciate if someone could help me suppress this dialog box. Thank you!

(The Dialog Box)

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
G K
  • 11
  • 1
  • I ran your code and it works as expected without the popup. there must be more code you're not providing here. look for anything that says [`alert`](https://www.w3schools.com/js/js_popup.asp) – Jeff Puckett Mar 21 '17 at 20:49
  • @JeffPuckettII , when I originally ran the code, I used code similar to [what I found here](http://stackoverflow.com/questions/27716499/how-to-call-a-php-script-function-on-a-html-button-click). The first answer on this thread does have an `alert` function, but I have since removed it. Would it be at all possible that the dialog box is a remnant from the first file? I will double check to ensure that I do not have any alert function. Thanks for your help. – G K Mar 21 '17 at 21:25
  • @JeffPuckettII . I just discovered something extremely strange. When I click the button on my iPhone, and on Chrome running in incognito, the dialog box does not appear. It only appears for my profile on Chrome. It is possible that it has something to do with the setting "prevent this page from creating additional dialog boxes" in Chrome... Either way, I think that the problem is resolved as of now. If I do not receive dialog boxes on any other browser in the future, it shouldn't be a problem. Thanks again for your help. – G K Mar 21 '17 at 21:35
  • it's probably just cached. in your browser, force reload with Shift+F5 – Jeff Puckett Mar 21 '17 at 22:24

0 Answers0