Hi,
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:
-> This works fine, but no download dialog pops up in the browser, the response arrives as xhr.responseTex t
2) A hidden POST Form
And trigger it like this:
But now the password is not transmitted
Can I somehow attach Basic authentication to above form?
Question: What is the correct approach?
Thanks
Marcel
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:
Code:
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
Code:
<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>
Code:
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
Comment