【发布时间】:2014-09-19 17:52:31
【问题描述】:
我有一个关于 JQuery Ajax 的问题,我在网上研究了一些示例,这些示例将 ajax 代码和静态 web 方法放在同一个 asp.net 页面中。我想做的是将ajax代码放在ascx控件中,并将静态webmethod放在包含控件的aspx页面中。可行吗?从我的测试中,我遇到了“服务器响应状态为 404”的问题。
静态网页方法:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public static List<AppUtils.vAdviseComponent> GetPDFReport()
{
//AppUtils.vAdvise.GetAllComponents(currentAssembelyID);
List<AppUtils.vAdviseComponent> assebmblyCompList = null;
assebmblyCompList = AppUtils.vAdvise.GetAllComponents(14);
return assebmblyCompList;
}
控件中的JQuery ajax代码
var tablecontent;
$j(function onSuccess(data) {
tablecontent = {
content: [
{
fontsize: 8,
table: {
headerrows: 1,
widths: ['auto', 'auto', 'auto', 'auto', 'auto'],
body: [
[{ text: 'id', bold: true }, { text: 'component name', bold: true }, { text: 'cage code', bold: true },
{ text: 'nsn', bold: true }, { text: 'part number', bold: true}],
]
}
}
]
};
tablecontent.content[0].table.body.push("shit");
});
$j("#pdfExtractBtn").button().on("click", function getPDFSummary() {
$j.ajax({
type: "post",
url: "vAdviseConfigurations.aspx/getPDFReport",
data: "{}",
datatype: "json",
contenttype: "application/json; charset=utf-8",
success: onSuccess,
error: function () {
alert("There was an error");
}
});
});
所以我的问题是我必须将 ajax 代码和 web 方法放在同一个 asp.net 页面中吗?提前致谢!
【问题讨论】:
标签: javascript jquery asp.net ajax json