473,624 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to force browser download dialog

2 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. var link = "http://.....";
  2. var base = base64Encode("k320i:xxxxx");
  3. var xhr = new XMLHttpRequest();
  4.   var async = false;
  5.   xhr.open("POST", link, async);
  6.   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  7.   xhr.setRequestHeader("Authorization", "Basic " + base);
  8.   xhr.send("a=XXXX");
-> This works fine, but no download dialog pops up in the browser, the response arrives as xhr.responseTex t

2) A hidden POST Form
Expand|Select|Wrap|Line Numbers
  1. <form id="downloadFormPOST" action="http://localhost:8080/io/rest/stat/k320i/2008-10-19/2009-10-20T12:00/test.csv" method="post" target="_blank">
  2.   <input type="hidden" name="_loginName" value="k320i">
  3.   <input type="hidden" name="_password" value="xxxx">
  4. </form>
And trigger it like this:
Expand|Select|Wrap|Line Numbers
  1. var downloadForm = window.document.forms['downloadFormPOST'];
  2.     downloadForm.submit();
But now the password is not transmitted
Can I somehow attach Basic authentication to above form?

Question: What is the correct approach?


Thanks
Marcel
Nov 17 '09 #1
3 5023
acoder
16,027 Recognized Expert Moderator MVP
What's the header set to for the CSV page? If you make a normal GET request, does it work?
Nov 18 '09 #2
swand9
2 New Member
Hi again,

the "2) A hidden POST Form" works!
It was my mistake on server side (a Java REST servlet) during parsing the form data.

But "1) Ajax" I didn't find a way to popup the browser download dialog during a Ajax response inside the browser (via Javascript)

So I'm using now solution 2).

I'm still curious: How to attach HTTP basic authentication to the <form> markup?

thanks
Marcel
Nov 18 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
http://www.peej.co.uk/articles/http-...tml-forms.html - a bit experimental, but should help.
Nov 19 '09 #4

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

Similar topics

1
1995
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename=" &" & StrFileName Now the it works fine in ie5.5 sp2 but no ie5.5 sp1 it prompts the user twice the open dialog box.
1
4924
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename=" &" & StrFileName Now the it works fine in ie5.5 sp2 but no ie5.5 sp1 it prompts the user twice the open dialog box.
4
21932
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of play it without having to right-click and save. How can I force the browser to pop up the "save file as" dialog box instead of playing it? I know that I can encapsulate it in a zip file which will download and open WinZip. Thanks
0
2103
by: PJS | last post by:
Thanks in advance. I have a site which generates a user specific XML document. The user then selects "Save to PC" which then forces the browser to show the "save/download" dialog box. The code used is as follows: Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName) Response.ContentType = "text/XML" Response.WriteFile(fileName)
2
3031
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents they successfuly download. My problem revolves around detecting a successful download, the steps I take to handle the download are as follows:
1
1547
by: greg | last post by:
Hi I have a link on a page that points to a file inside the site that I want to be downloaded loke in page_load I write linkFile.NavigateUrl = Request.ApplicationPath + "/somepath/file.iif"; This file is a text file so when user clicks onthat link it displays in the browser
4
3829
by: Richard Wilde | last post by:
How do I force an XML document to be downloaded from a web browser to a client? The XML document will come ideally from a dataset but if this is not possible then I can save off the XML document to the server and read it back in to send to the clients browser. I have somethink like this but am struggling to send the XML... With HttpContext.Current.Response
0
2662
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL encoding too, but with no success. Can someone provide details on how to handle the 2-byte char URLs and download the files? Appreciate your suggestions/help in resolving it. Here is my code:
1
1807
by: JP SIngh | last post by:
Hi All We have a page which we want to allow our users to download files. Can someone point to peice of code that we can use to force the download as opposed to opening the files in the browser. Only one issue here the code need to work with UNC path like \\myserver\files\ and not just c:\inetpub\wwwroot\files
0
8236
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.