marknery
marknery

Reputation: 1543

returning pdf jquery

I am using jQuery to send JSON back to the server and it sends back a pdf report, however it is not downloading the pdf the response header and javascript are below.

$('#log-report').live("click", function () {
var query = {

    'projectID': $('#ProjectID').val(),
    'lessontypeID': $('#lessonTypeID').val(),
    'phaseID': $('#phaseID').val(),
    'assetTypeID': $('#assetTypeID').val(),
    'dateFrom': $('#dateFrom').val(),
    'dateTo': $('#dateTo').val()
};

$.ajax({
    url: '/Report/getQueryPdf',
    data: query,
    type: 'GET',
    contentType: 'application/json, charset=utf-8'

});
});

Cache-Control:private
Connection:Close
Content-Disposition:attachment; filename=Lessons_Learned_Report.pdf
Content-Length:77211
Content-Type:application/pdf
Date:Tue, 03 Jan 2012 19:47:44 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0

Upvotes: 1

Views: 331

Answers (1)

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114347

The browser usually handles the MIME type when a page is requested. Because you're using AJAX you're allowing the AJAX request to handle the response. The browser ignores it.

You need to pass the pdf URL to the browser using document.location= in order to allow the browser to "naturally" handle the request.

Upvotes: 1

Related Questions