【问题标题】:Do we have to put the ajax code and web method in the same asp.net page?我们是否必须将 ajax 代码和 web 方法放在同一个 asp.net 页面中?
【发布时间】: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


    【解决方案1】:

    根据我的测试和在线示例,我认为我们不能在两个单独的页面类中进行 JQuery AJAX。

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 2011-02-02
      • 1970-01-01
      • 2014-05-05
      • 2011-08-30
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多