1
我有一個關於JQuery Ajax的問題,我研究了一些在線的例子,它們將ajax代碼和靜態web方法放在同一個asp.net頁面中。我想要做的是將ajax代碼放入ascx控件中,並將靜態webmethod放入包含該控件的aspx頁面中。這可行嗎?從我的測試中,我得到了「服務器響應404狀態」的問題。我們是否必須將ajax代碼和web方法放在同一個asp.net頁面中?
靜態網頁的方法:在控制
[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頁?提前致謝!