title: Play Framework: Controller action runs every load
body: <p>Does anyone know why my action runs every time I reload a page. I have a page with a button that should run when I click on it. But now it seems to run when I load the page.</p>
  
  <p>Here is my button and javascript in file <em>deliverables.scala.html</em></p>
  
  <pre><code>&lt;input type="button" class="btn success" id="add" value="Export to Excel" onclick="JavaScript:generateExcelClick()" /&gt;
  
  &lt;script&gt;
  function generateExcelClick(event)
  {
     window.location = "@Application.generateExcel(currentPage)";
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And my controller:</p>
  
  <pre><code>public static void generateExcel(List&lt;Infoobject&gt; list) {
      ...creating a file (works)
      ...No return
  }
  </code></pre>
  
  <p>How can I change this code so it only runs when I click on the button? The action should not render an another page or something like that. I only want to generate a file.</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I've tried @controllers.Application.generateExcel(currentPage); and @Application.generateExcel(currentPage); in my Javascript function, but it's still creating the file even if I don't click the button.</p>
  
  <p>I have also checked that @Application.generateExcel(currentPage); doesn't runs from an another site och function.</p>
  
  <p>Someone, please?</p>