Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:02:26+00:00 2026-06-16T02:02:26+00:00

I want to perform a javascript xhr request for a png file from a

  • 0

I want to perform a javascript xhr request for a png file from a C# webserver which I wrote.
Here is the code I use

    var imgUrl = "http://localhost:8085/AnImage.png?" + now;
    var request = new XMLHttpRequest();
    request.open('GET', imgUrl, false);
    request.send(); // this is in a try/catch

On the server-side I send back the file and add a Content-Disposition header.
I obtain the following response

The headers obtained in the response, with Firebug

I made sure that Content-Disposition was attached in the headers after the Content-Type (the screenshot is from Firebug, which appends in alphabetical order).

The results is that no dialog box is triggered, am I missing something in the response?

edit:
I want to perform everything in javascript for several reasons.
First: I don’t want to show the image and I want to keep everything behind the curtain.
Second: when requesting the image I want the Content-Disposition to be added only on particular requests. Such requests are marked with a “Warning” header with value “AttachmentRequest”

request.setRequestHeader("Warning","AttachmentRequest");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:02:27+00:00Added an answer on June 16, 2026 at 2:02 am

    I don’t think Content-Disposition triggers any file save dialog when the request is via XHR. The use of XHR suggests you’re going to handle the result in code.

    If you want the user to be prompted to save the image to a file, I’ve used this technique successfully:

    window.open("http://localhost:8085/AnImage.png?" + now);
    

    It has the downside that it flashes a blank open window briefly until the header arrives, then the new window closes and the “save file” dialog box appears.

    Using an iframe may prevent the window flashing:

    var f = document.createElement('iframe');
    f.style.position = "absolute";
    f.style.left = "-10000px";
    f.src = "http://localhost:8085/AnImage.png?" + now;
    document.body.appendChild(f);
    

    Separately, I wonder what effect (if any) Content-Disposition has on the handling of an img element:

    var img = document.createElement('img');
    img.style.position = "absolute";
    img.style.left = "-10000px";
    img.src = "http://localhost:8085/AnImage.png?" + now;
    document.body.appendChild(img);
    

    I haven’t tried that, but the browser might respect the header. You’d need to be sure to test on all of the browsers you want to support.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JavaScript which I want to perform a REST Request (GET) to
I want to perform changes in the code which was developed using iOS 3.0,
I am having two functions in my JavaScript code, and I want to perform
I have a multiple row of buttons in my javascript code which goes from
I want my code so that if a specific var exists it will perform
I have some JavaScript code which I want to make more readable. However, due
I want perform a easy task in android, which when receiving a call the
I want to perform an jquery request to php and then I want php
I want to perform a printf() to display when the currently executing code was
I want to perform some logic in JavaScript when users click on the span

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.