Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    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');

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,609
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 .

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •