I need to downlad a server side generated csv file with Javascript.
I need to send the login name and password and I don't want to use GET as I want to avoid a visible password in the URL.
Further, my displayed HTML page should not reload.
This is what I have tried:
1) Ajax:
Expand|Select|Wrap|Line Numbers
- var link = "http://.....";
- var base = base64Encode("k320i:xxxxx");
- var xhr = new XMLHttpRequest();
- var async = false;
- xhr.open("POST", link, async);
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xhr.setRequestHeader("Authorization", "Basic " + base);
- xhr.send("a=XXXX");
2) A hidden POST Form
Expand|Select|Wrap|Line Numbers
- <form id="downloadFormPOST" action="http://localhost:8080/io/rest/stat/k320i/2008-10-19/2009-10-20T12:00/test.csv" method="post" target="_blank">
- <input type="hidden" name="_loginName" value="k320i">
- <input type="hidden" name="_password" value="xxxx">
- </form>
Expand|Select|Wrap|Line Numbers
- var downloadForm = window.document.forms['downloadFormPOST'];
- downloadForm.submit();
Can I somehow attach Basic authentication to above form?
Question: What is the correct approach?
Thanks
Marcel