CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   xmlhttpRequest download dynamic file (http://www.codingforums.com/showthread.php?t=281826)

kobolds 11-10-2012 05:33 PM

xmlhttpRequest download dynamic file
 
I having problem to download pdf from report server using xMLHTTPrequest

var xhReq = new XMLHttpRequest();
var m_str = 'http://win2012svr:8080/ReportServer?%2fxreport%2fcodedetailed&D1=2012-09-01&D2=2012-09-30&RATE=PUBLIC&rs:Command=Render&rs:Format=PDF';

xhReq.open("GET", m_str, true);


xhReq.onload = function(e) {
if (this.readyState == 4 && this.status == 200) {
var m_file = this.response;
alert(m_file);

}
};
xhReq.send();



using firebug
header return
Response Headers
Cache-Control private
Content-Disposition attachment; filename="codedetailed.pdf"
Content-Length 3757
Content-Type application/pdf
Date Sat, 10 Nov 2012 17:30:32 GMT
Expires Sat, 10 Nov 2012 17:29:32 GMT
FileExtension pdf
Last-Modified Sat, 10 Nov 2012 17:30:33 GMT

but no this return from response .

what should I do to make it work . Please help

devnull69 11-11-2012 07:56 AM

Is the current page (the page from which you showed the Javascript code) on the exact same server as the requested information? So has the current page been served from http://win2012svr:8080?

If not, you will most probably get a security exception because of violation of the same origin policy of your browser.

If you have full access to this server you could set the response header to allow other origins. In PHP for example you can do it like this (if the current page is from http://www.example.com)
Code:

header('Access-Control-Allow-Origin: http://www.example.com');

felgall 11-11-2012 09:41 PM

If you don't have access to update that on the server where the PDF is located then the aletrnative is to have the JavaScript call a script that is on the same server as the web page loaded from and have that script get the PDF from the remote server and pass it back.

kobolds 11-12-2012 12:55 AM

I not sure whether that the problem cause I try to catch the error , there's no error and the script run until finish point.

I wonder if xmlhttprequest able to handle dynamic file download . have anyone try before?

kobolds 11-12-2012 10:50 AM

when I run from chrome development tools. I get this error,
Origin http://win2012svr is not allowed by Access-Control-Allow-Origin.

I have tried code from this site . also not working . I getting error 'Woops, there was an error making the request'
http://www.html5rocks.com/en/tutorials/cors/


i had add "Access-Control-Allow-Origin" value="*" to HTTP response header on IIS also not working

there's no setting on reportserver other that ssrs related function .

I have no idea. I have tried alot but still the same . please help me

kobolds 11-14-2012 11:09 AM

I give up . my solution is change the port of report server from 8080 to 80 (default) . problem solved no more Access-Control-Allow-Origin problem .
of course this solution can only work if webserver and sql server in one host .

AndrewGSW 11-14-2012 11:23 AM

If you just want to download the pdf then wouldn't a simple link work:

Code:

<a href="http://win2012svr:8080/ReportServer?%2fxreport%2fcodedetailed&D1=2012-09-01&D2=2012-09-30&RATE=PUBLIC&rs:Command=Render&rs:Format=PDF">Download</a>
This requires clicking, of course, but I suppose something like a hidden iframe might be used to trigger the download..?


All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.