i have another problem. basically the question is: how do i make sure a file is downloaded instead of opened?
but i'll explain the situation. i'm trying to download a file using a button. when clicked, i call an ajax-request to a php-page where i dynamically create a ".pmp"-file. then it returns the name of the file. last, i open the file using document.location.
here is my ajax request and the code to redirect my page.
Expand|Select|Wrap|Line Numbers
- function Exportfile(){
- var data = "--- content of 'a lot of data' goes here ---";
- XMLHttpRequestObject = GetXmlHttpObject();
- var sended = "data="+data;
- var download = "download.php";
- XMLHttpRequestObject.open("POST",download,true);
- XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- XMLHttpRequestObject.setRequestHeader("Content-length", sended.length);
- XMLHttpRequestObject.setRequestHeader("Connection", "close");
- XMLHttpRequestObject.onreadystatechange = function(){
- if (XMLHttpRequestObject.readyState == 4){
- filename = XMLHttpRequestObject.responseText;
- document.location = filename;
- }
- }
- XMLHttpRequestObject.send(sended);
- }