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.
Here is my button and javascript in file deliverables.scala.html
<input type="button" class="btn success" id="add" value="Export to Excel" onclick="JavaScript:generateExcelClick()" />
<script>
function generateExcelClick(event)
{
window.location = "@Application.generateExcel(currentPage)";
}
</script>
And my controller:
public static void generateExcel(List<Infoobject> list) {
...creating a file (works)
...No return
}
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.
Thanks!
Edit
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.
I have also checked that @Application.generateExcel(currentPage); doesn't runs from an another site och function.
Someone, please?