title: Run Django function from Javascript command
body: <p>I'm trying to have Django to run a function when I tell it based off a JavaScript button. How do I accomplish this? Where do I write the Django function?</p>
  
  <h3>JavaScript in main.html:</h3>
  
  <pre><code>            function mainFunction(){
              alert("Beginning API Main Function");
  
                  $.ajax({
                      type: 'POST',
                      url: 'livestream/postdata/',
                      success: function(){alert('DONE!');},
                      error:function(){alert('ERROR!');},
              });
              alert("ENDING API MAIN FUNCTION");
          }
  </code></pre>
  
  <h3>Urls.py:</h3>
  
  <pre><code>    url(r'^postdata$', 'livestream.views.postdata', name='postdata')
  </code></pre>
  
  <h3>Views.py:</h3>
  
  <pre><code>def postdata(request):
  
      r = ...api... (I know that the api works)
      print(r.text)
  </code></pre>
  
  <p>When I run the function 'mainFunction()' I get the two alerts and then another that says 'ERROR'. Why is this?</p>