我的 asp.net 网站上出现 ajax 错误

发布于 2024-12-20 23:34:27 字数 3605 浏览 1 评论 0原文

我开发了一个asp.net站点。在它的大部分页面中,我在客户端站点中使用jquery库的$.ajax方法,在服务器端使用web方法。

当我在本地计算机上运行我的网站时,一切正常,但是当我将其上传到我的主机上时,大多数 ajax 请求都会出错。

这是一个示例:

EX:我有一个灵活的网格,希望在文档准备好时将数据加载到其中,但是发生了错误,我通过 firebug 捕获了它:

The method 'FetchCountryList' returns a value of type 'System.Xml.XmlDocument', which
cannot be serialized as Xml. Original error: Unable to generate a temporary class 
(result=1). error CS2001: Source file 'C:\WINDOWS\TEMP\d2h0eyni.0.cs' could not be 
found error CS2008: No inputs specified 

我需要帮助来解决此错误

这是我在客户端的代码:

               $("#GrdCountry").flexigrid({
                    url: 'CountryDefinition.aspx/FetchCountryList',
                    dataType: 'xml',
                    colModel: [
                        { display: 'Name', name: 'Name', width: 210, sortable: true, align: 'left' },
                        { display: 'Code', name: 'Code', width: 100, sortable: true, align: 'left' },
                        { display: 'Capital', name: 'Capital', width: 210, sortable: true, align: 'left' },
                        { display: 'Actions', width: 100, align: 'Center'}],
                    buttons: [
                        { name: 'Add', bclass: 'add', onpress: addOpr },
                        { separator: true}],
                    searchitems: [
                        { display: 'Name', name: 'Name', isdefault: true },
                        { display: 'Capital', name: 'Capital'}],
                    sortname: "Name",
                    sortorder: "asc",
                    usepager: true,
                    //title: 'Countries',
                    useRp: true,
                    rp: 10,
                    resizable: false,
                    showTableToggleBtn: false,
                    width: 783,
                    height: 330
                });

这是我在服务器端的代码:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    public static XmlDocument FetchCountryList(int page, int rp, string sortname, string sortorder, string query, string qtype)
    {
        CountryBL CountryBLO = new CountryBL();
        XDocument xmlDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),

                new XElement("rows",
                    new XElement("page", page.ToString()),
                    new XElement("total", CountryBLO.Load().Count.ToString()),
                    CountryBLO.Load(page, rp, sortname, sortorder, query, qtype).Select(row => new XElement("row", new XAttribute("Id", row.Id.ToString()),
                                                      new XElement("cell", row.Name.ToString()),
                                                      new XElement("cell", row.Code.ToString()),
                                                      new XElement("cell", row.Capital.ToString()),
                                                      new XElement("cell", "<img id='imgEdit' lang='" + row.Id.ToString() + @"' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/edit.png' />
                                                                            <img id='imgDelete' lang='" + row.Id.ToString() + "' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/delete.gif' />")                        
                                                    )
                                )
                    )
        );
        return Tools.XDocumentToXmlDocument(xmlDoc);
    }

谢谢,阿里

I've developed an asp.net site.in most pages of it , I use the $.ajax method of jquery library in cliend site , and web method in server side.

When I run my site on local computer , is goes right , but when I upload it on my host , most of ajax request for goes with error.

This is an example :

EX : I've a flexi grid and want to load data into it when is document ready , but and error uccurred and i catch it by firebug :

The method 'FetchCountryList' returns a value of type 'System.Xml.XmlDocument', which
cannot be serialized as Xml. Original error: Unable to generate a temporary class 
(result=1). error CS2001: Source file 'C:\WINDOWS\TEMP\d2h0eyni.0.cs' could not be 
found error CS2008: No inputs specified 

I want help to solve this error

This is my code in client side :

               $("#GrdCountry").flexigrid({
                    url: 'CountryDefinition.aspx/FetchCountryList',
                    dataType: 'xml',
                    colModel: [
                        { display: 'Name', name: 'Name', width: 210, sortable: true, align: 'left' },
                        { display: 'Code', name: 'Code', width: 100, sortable: true, align: 'left' },
                        { display: 'Capital', name: 'Capital', width: 210, sortable: true, align: 'left' },
                        { display: 'Actions', width: 100, align: 'Center'}],
                    buttons: [
                        { name: 'Add', bclass: 'add', onpress: addOpr },
                        { separator: true}],
                    searchitems: [
                        { display: 'Name', name: 'Name', isdefault: true },
                        { display: 'Capital', name: 'Capital'}],
                    sortname: "Name",
                    sortorder: "asc",
                    usepager: true,
                    //title: 'Countries',
                    useRp: true,
                    rp: 10,
                    resizable: false,
                    showTableToggleBtn: false,
                    width: 783,
                    height: 330
                });

and this is my code in server side :

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    public static XmlDocument FetchCountryList(int page, int rp, string sortname, string sortorder, string query, string qtype)
    {
        CountryBL CountryBLO = new CountryBL();
        XDocument xmlDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),

                new XElement("rows",
                    new XElement("page", page.ToString()),
                    new XElement("total", CountryBLO.Load().Count.ToString()),
                    CountryBLO.Load(page, rp, sortname, sortorder, query, qtype).Select(row => new XElement("row", new XAttribute("Id", row.Id.ToString()),
                                                      new XElement("cell", row.Name.ToString()),
                                                      new XElement("cell", row.Code.ToString()),
                                                      new XElement("cell", row.Capital.ToString()),
                                                      new XElement("cell", "<img id='imgEdit' lang='" + row.Id.ToString() + @"' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/edit.png' />
                                                                            <img id='imgDelete' lang='" + row.Id.ToString() + "' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/delete.gif' />")                        
                                                    )
                                )
                    )
        );
        return Tools.XDocumentToXmlDocument(xmlDoc);
    }

Thanks , Ali

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2024-12-27 23:34:27

尝试返回一个字符串。

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    public static String FetchCountryList(int page, int rp, string sortname, string sortorder, string query, string qtype)
    {
        CountryBL CountryBLO = new CountryBL();
        XDocument xmlDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),

                new XElement("rows",
                    new XElement("page", page.ToString()),
                    new XElement("total", CountryBLO.Load().Count.ToString()),
                    CountryBLO.Load(page, rp, sortname, sortorder, query, qtype).Select(row => new XElement("row", new XAttribute("Id", row.Id.ToString()),
                                                      new XElement("cell", row.Name.ToString()),
                                                      new XElement("cell", row.Code.ToString()),
                                                      new XElement("cell", row.Capital.ToString()),
                                                      new XElement("cell", "<img id='imgEdit' lang='" + row.Id.ToString() + @"' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/edit.png' />
                                                                            <img id='imgDelete' lang='" + row.Id.ToString() + "' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/delete.gif' />")                        
                                                    )
                                )
                    )
        );

StringBuilder builder = new StringBuilder();
        using (TextWriter writer = new StringWriter(builder))
        {
            doc.Save(writer);
        }

        return builder.ToString();
    }

Try returning into a String.

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    public static String FetchCountryList(int page, int rp, string sortname, string sortorder, string query, string qtype)
    {
        CountryBL CountryBLO = new CountryBL();
        XDocument xmlDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),

                new XElement("rows",
                    new XElement("page", page.ToString()),
                    new XElement("total", CountryBLO.Load().Count.ToString()),
                    CountryBLO.Load(page, rp, sortname, sortorder, query, qtype).Select(row => new XElement("row", new XAttribute("Id", row.Id.ToString()),
                                                      new XElement("cell", row.Name.ToString()),
                                                      new XElement("cell", row.Code.ToString()),
                                                      new XElement("cell", row.Capital.ToString()),
                                                      new XElement("cell", "<img id='imgEdit' lang='" + row.Id.ToString() + @"' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/edit.png' />
                                                                            <img id='imgDelete' lang='" + row.Id.ToString() + "' style='cursor:pointer;border:0px;' src='../../Storage/Images/FlexGrid/delete.gif' />")                        
                                                    )
                                )
                    )
        );

StringBuilder builder = new StringBuilder();
        using (TextWriter writer = new StringWriter(builder))
        {
            doc.Save(writer);
        }

        return builder.ToString();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文