我的问题是,当我点击按钮调用“打印”时,它将从表中获取数据并通过jQuery发送ajax来调用页面方法来创建pdf,但没有任何反应。
这是我的代码
客户
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');
}
});
}
这是我的服务器代码
[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");
}
但这没有任何反应。我做错了什么?
答案 0 :(得分:0)
根据ajax调用,您至少应该获得成功或错误。
尝试调试服务器代码怎么样。