Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2012, 05:33 PM   PM User | #1
kobolds
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kobolds is an unknown quantity at this point
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
kobolds is offline   Reply With Quote
Old 11-11-2012, 07:56 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
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');
devnull69 is offline   Reply With Quote
Old 11-11-2012, 09:41 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-12-2012, 12:55 AM   PM User | #4
kobolds
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kobolds is an unknown quantity at this point
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 is offline   Reply With Quote
Old 11-12-2012, 10:50 AM   PM User | #5
kobolds
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kobolds is an unknown quantity at this point
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 is offline   Reply With Quote
Old 11-14-2012, 11:09 AM   PM User | #6
kobolds
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kobolds is an unknown quantity at this point
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 .
kobolds is offline   Reply With Quote
Old 11-14-2012, 11:23 AM   PM User | #7
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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..?
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:44 AM.


Advertisement
Log in to turn off these ads.