title: JSON and Python
body: <p>I am developing a web interface for Arduino, using Python. For automatic updates and display, I use JSON. I have a very interesting problem.</p>
  
  <p>The following code sends the command to a python function, if a command exists. Then, whether a command was sent to the function or not, the function checks for updates from the Arduino by calling another function.</p>
  
  <p>Here is what I can't find any explanation to: in the first and only condition of the update() function, if I remove the line that says alert('hey'); the python function is not called anymore. But if I do write alert('hey'); after the JSON request, it works fine, the function is called and the arduino gets the message. </p>
  
  <p>Anyone has an idea why?</p>
  
  <pre><code>function update(command=0) {
  
      // if a command is passed, send it
  
      if (command!=0) {
          $.getJSON('/action?command='+command);
          alert('hey'); // if I remove this, the action function is not called. Why?
      }
  
      // read from the read function, no matter what
  
      $.getJSON('/read', {}, function(data) {
          if (data.state != 'failure' &amp;&amp; data.content != '') {
              $('.notice').text(data.content);
              $('.notice').hide().fadeIn('slow');
              setTimeout(function () { $('.notice').fadeOut(1000); }, 1500);
          }
          setTimeout(update, 5000); // next update in 5 secs
      });
  }
  
  update(); // for the first call on page load
  </code></pre>