Ajax错误在我的asp.net网站

本文关键字:net 网站 asp 我的 错误 Ajax | 更新日期: 2023-09-27 18:17:37

我开发了一个asp.net网站。在大多数页面中,我在客户端使用jquery库中的$.ajax method,在服务器端使用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);
    }

谢谢你,Ali

Ajax错误在我的asp.net网站

尝试返回一个字符串

[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();
    }