开发者

Downloading PDF File with AJAX/MVC 3

开发者 https://www.devze.com 2023-04-07 19:47 出处:网络
Basically the issue is this: I have a pdf file that I am requesting from a server based on the currently logged in user\'s ID and the OID. In order to get the OID, I have to parse a value from a HTML

Basically the issue is this:

I have a pdf file that I am requesting from a server based on the currently logged in user's ID and the OID. In order to get the OID, I have to parse a value from a HTML table based on the button the user clicks on and then send it to the home controller. Then an API call is run to grab the OID. Another AP开发者_StackOverflowI call is then made with the OID to pull the PDF file. AJAX is used to send the the parsed HTML value to the home controller using this code here:

        $('.pdfPrint').live('click', function () {
            $(this).addClass('selectedDetails');
            var parent = $('.selectedDetails').parents('tr');
            var tr = $(this).parents('tr');
            var td = tr.children();
            var i = 0;
            td.each(function () {
                $(this).addClass('tdGrid' + i);
                i++;
            });
            var primaryReference = "";
            primaryReference = $('.tdGrid1').text();
            gridClassRemover();
            $.ajax({ // create an AJAX call...
                data: { pReference: primaryReference }, // get the form data
                type: "POST", // GET or POST
                url: "/Home/PrintFromGrid", // the file to call
                success: function (response) { // on success..
                    callTrackDialog();
                    // update the DIV                         
                },  // end of success
                error: function () {
                    alert('An error has occurred. If this problem persists please contact support.');
                }
            });  // end of .ajax
        });


Yes, don't use AJAX to download files. Simply redirect in javascript by passing the pReference as query string parameter:

window.location.href = '@Url.Action("PrintFromGrid", "Home")?pReference=' + encodeURIComponent(primaryReference);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号