473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

javascript document.location to download a file

Ciary
247 Expert 100+
hey all,

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
  1.             function Exportfile(){
  2.                                 var data = "--- content of 'a lot of data' goes here ---";
  3.  
  4.                 XMLHttpRequestObject = GetXmlHttpObject();
  5.                 var sended = "data="+data;
  6.                 var download = "download.php";
  7.                 XMLHttpRequestObject.open("POST",download,true);
  8.  
  9.                 XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  10.                 XMLHttpRequestObject.setRequestHeader("Content-length", sended.length);
  11.                 XMLHttpRequestObject.setRequestHeader("Connection", "close");
  12.  
  13.                 XMLHttpRequestObject.onreadystatechange = function(){
  14.                     if (XMLHttpRequestObject.readyState == 4){
  15.                         filename = XMLHttpRequestObject.responseText;
  16.                         document.location = filename;
  17.                     }
  18.                 }
  19.  
  20.                 XMLHttpRequestObject.send(sended);
  21.             }
does anyone know how i can do this?
May 8 '09 #1
1 12754
Ciary
247 Expert 100+
never mind. i found a solution on the last page of my search on the forum. i was attracted to the number of views.

anyway, here is what you need to do
May 8 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John Taylor-Johnston | last post by:
This will give me the source of the current page. <a herf="javascript:document.location = 'view-source:'+document.location">testpage.htm</a> I want to display the source of another page, using...
8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
2
by: yogesh.bhardwaj | last post by:
Hello all I am trying to modify the link URL when a user clicks on the link. Following is the code: <a onClick="document.location.href=modifyURL(this.href);" href="SOME_DYNAMIC_URL"...
2
by: John | last post by:
I have some code that changes a PDF file in another frame using: parent.frame.document.location.href = "PDF File" This code works fine the first time it is called. But if a PDF file is in that...
2
by: Graham | last post by:
I'm not very experienced with Javascript, and I'm trying to determin a current web page's path. If I use document.location, it returns http://domain.com/path/to/file I only want to see...
0
by: cephelo | last post by:
I'm trying to incorporate the document location into a basic XSL transformation on the client-side (Firefox and IE primarily). Currently I hack it in using Javascript.. hardly ideal. Is there a...
2
by: itmanager8815 | last post by:
I had a question regarding the use of document.location. I have the following script: <HTML> <BODY> <SCRIPT LANGUAGE=JAVASCRIPT> window.status=''; ...
4
by: DNK2007 | last post by:
Hi all Look at the following code <html> <head> <script type="text/javascript"> document.location="http://www.gmail.com"; alert(document.location); </script>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.