[英]Do we have to put the ajax code and web method in the same asp.net page?
I am having a question about JQuery Ajax, I researched some examples online, which put ajax code and static web method in the same asp.net page. 我有一个关于JQuery Ajax的问题,我在线研究了一些示例,这些示例将ajax代码和静态Web方法放在同一个asp.net页面中。 What I am trying to do is to put ajax code in ascx control, and the static webmethod in a aspx page that contains the control.
我正在尝试将ajax代码放入ascx控件中,并将静态web方法放在包含该控件的aspx页面中。 Is it feasible?
可行吗 From my test, I got problem that "the server responded with a status of 404".
通过测试,我遇到了“服务器响应状态为404”的问题。
static web method: 静态网页方法:
[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 code in the control 控件中的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");
}
});
});
so my question is that do I have to put the ajax code and web method in the same asp.net page? 所以我的问题是,我是否必须将Ajax代码和Web方法放在同一asp.net页面中? Thanks in advance!
提前致谢!
通过测试和在线示例,我认为我们不能在两个单独的页面类中执行JQuery AJAX。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.