jQuery-Ajax-post创建PDF
我的问题是,当我点击按钮调用“Print”时,它将从表中获取数据,并通过jQuery向callpage方法发送ajax来创建pdf,但什么也没发生 这是我的密码 客户jQuery-Ajax-post创建PDF,jquery,asp.net,pdf,Jquery,Asp.net,Pdf,我的问题是,当我点击按钮调用“Print”时,它将从表中获取数据,并通过jQuery向callpage方法发送ajax来创建pdf,但什么也没发生 这是我的密码 客户 function Print(button) { var arrDTO = new Array(); var printButton = $(button); var $targetTable = printButton.parent(
function Print(button) {
var arrDTO = new Array();
var printButton = $(button);
var $targetTable = printButton.parent().parent().find('table');
var $tr = $targetTable.find('tbody tr');
for (var i = 0; i < $tr.length; i++) {
var newObj = {};
var td = $($tr[i]).find('td');
newObj.BugID = $(td[0]).find('a').html().trim();
newObj.Title = $(td[2]).find('a').html().trim();
newObj.HouseName = $(td[3]).html().trim();
newObj.RoomName = $(td[4]).html().trim();
newObj.ThePersonResponsibleName = $(td[5]).html().trim();
newObj.FAGName = $(td[6]).html().trim();
newObj.CompanyName = $(td[7]).html().trim();
newObj.Reminders = $(td[8]).html().trim();
newObj.Delayed = $(td[9]).html().trim();
newObj.Appendix = $(td[10]).html().trim();
newObj.MoreInfo = $(td[11]).html().trim();
newObj.DeadLine = $(td[12]).html().trim();
newObj.Comment = $(td[13]).find('input[type=\"text\"]').val().trim();
newObj.Retention = $(td[14]).find('label').html().trim();
newObj.Discount = $(td[15]).html().trim();
newObj.Balance = $(td[16]).html().trim();
newObj.StatusName = $(td[17]).html().trim();
arrDTO[i] = newObj;
//alert('row ' + (i + 1) + ' ' + arrDTO[i].BugID);
}
var DTO = { 'issueType2ViewModel': arrDTO };
$.ajax({
"type": "POST",
"url": "IssuesType2.aspx/Print",
"data": JSON.stringify(DTO),
"contentType": "application/json; charset=utf-8",
"dataType": "json",
"success": function (data) {
alert('success');
//window.location = "/1.pdf";
},
"error": function (data) {
alert('Error');
}
});
}
但这一切都没有发生。我这样做有什么不对?基于ajax调用,您至少应该获得成功或错误 试着调试服务器代码怎么样
[System.Web.Services.WebMethod()]
public static void Print(Old_App_Code.ViewModel.IssueType2ViewModel[] issueType2ViewModel)
{
//HttpContext.Current.Request[
int projectID = 0;
int catID = 0;
if (HttpContext.Current.Request["pid"] != null)
{
projectID = Convert.ToInt32(HttpContext.Current.Request["pid"]);
if (HttpContext.Current.Request["Cat"] != null)
{
catID = Convert.ToInt32(HttpContext.Current.Request["Cat"]);
}
}
System.IO.FileStream fs = new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + "\\" + "Test.pdf", FileMode.Create);
Document doc = new Document(PageSize.A4_LANDSCAPE, 1, 1, 1, 1);
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.Add(new Paragraph("Hello World"));
doc.Close();
writer.Close();
HttpContext.Current.Response.ContentType = "pdf/application";
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=First PDF document.pdf");
HttpContext.Current.Response.Redirect("~/Test.pdf");
}