Hello,
Is here anyone familiar with sajax: http://absinth.modernmethod.com/sajax/index.phtml ?
I am trying to use sajax to force download a .txt file.
When using sajax I call a function containg print() to print something into a file (because I have necessary eader() settings to force download print() rather than printing on screen) it doesn't work but when I return a value from that php func into the JS func, the alert in JS func will work but if my php func contains print() it doesn't work.) so how to force download a file using sajax? please advice.
My php func is something like:
function download() {
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=blah.txt");
header("Pragma: no-cache");
header("Expires: 0");
print("some text here");
retrun true;
}
if I omit print() and retrun a value, the JS function will recognize the value, but as long as print() is there, nothing is working, I appreciate your advice.
If this is impossible with sajax then another way is hidden form like this:
To create a link to force download a txt file I create a link like this:
<a href="javascript:void(document.blah.submit())">Download it</a>
Then somewhere on the page I have:
<form name="blah" method="post" action="blah.php">
<input type="hidden" name="do" value="blah">
</form>
so that link pass ?do=blah to the same script and the secript will call the necessary function to force download a file. no problem until here.
but something similar:
<a href="javascript:void(document.dl_remlic.submit('1')">Do it</a>
the differenc of this that it passes a parameter (i.e. '1' in example above) to the dl_remlic hidden form which is something similar to the form above. But how the form should know that the parameter of this JS is 1 or whatever? I know I should pass '1' to a function that would define the value in a hidden field and then submit the form. but how to do so?
Thanks,