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 8706347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:35:32+00:00 2026-06-13T03:35:32+00:00

I am fairly new to AJAX. I am sending a request to server using

  • 0

I am fairly new to AJAX. I am sending a request to server using AJAX. The service returns a text file. But no download box appears when data is returned.
The rest service that returns the file is as follows:

@Path("/examples")
public class ExampleCodesRest {


    @POST
    @Path("/getcode")
    @Produces(MediaType.TEXT_PLAIN)
    public Response getCodes(@Context ServletContext context){

        String in=context.getRealPath("/WEB-INF/reports.jrxml");
        File file=new File(in);

        ResponseBuilder response = Response.ok((Object) file);
        response.header("Content-Disposition",
            "attachment; filename=\"file_from_server.log\"");
        return response.build();

    }
}

My AJAX call is as follows:

 $('a#link').click(function(event){
    event.preventDefault();
    $.ajax({
        url: '/reports/rest/examples/getcode',
        type: 'POST'
    });
}); 

The file downloads successful without AJAX.
With AJAX, it doesn’t download the file.Please advice.

  • 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-13T03:35:33+00:00Added an answer on June 13, 2026 at 3:35 am

    Advice is simple: you cannot download files via AJAX – it’s a security policy. I mean you can download the data, but you can’t save it to disk from JavaScript side.

    If you want to download a file on click, then you can just add href to you a tag. Or open a new window with file’s URL.

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

Sidebar

Related Questions

I'm fairly new to using AJAX in ASP.NET (although I am very familiar with
Im using DWR, which im fairly new to...I using ajax to submit a comment
I'm really new to using JSON to handle my Ajax Request and Response cycle.
I am fairly new to php and mysql but I have created a small
I'm fairly new to C++ standard library and have been using standard library lists
Disclaimer: I'm fairly new to AJAX! I've looked around, and I'm not sure which
I'm fairly new to JavaScript/jQuery/AJAX, so I suspect the issue is some typo I'm
We have a fairly robust ASP.NET app using quite a bit of AJAX, jQuery
I'm fairly new to facebook development, but have experience with PHP and JavaScript. I've
So I'm fairly new to jQueryMobile but I've managed to create a search bar

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.