Noz*_*oku 1 pdf ajax download asp.net-mvc-3
基本上问题是:
我有一个pdf文件,我根据当前登录用户的ID和OID从服务器请求.为了获得OID,我必须根据用户点击的按钮从HTML表中解析一个值,然后将其发送到家庭控制器.然后运行API调用以获取OID.然后使用OID进行另一个API调用以提取PDF文件.AJAX用于使用以下代码将解析的HTML值发送到家庭控制器:
$('.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
});
Run Code Online (Sandbox Code Playgroud)
是的,不要使用AJAX下载文件.只需通过传递pReferenceas查询字符串参数在javascript中重定向:
window.location.href = '@Url.Action("PrintFromGrid", "Home")?pReference=' + encodeURIComponent(primaryReference);
Run Code Online (Sandbox Code Playgroud)