2011-12-12 113 views
0

我已經開發了一個asp.net網站,在它的大部分頁面中,我使用的是庫的cliend網站,以及web方法在服務器端。我的asp.net網站上的ajax錯誤

當我在本地計算機上運行我的站點時,是正確的,但是當我將其上載到我的主機上時,大部分ajax請求都會出錯。

這是一個例子:

EX:我有一個彈性工作網格,希望將數據加載到它時,文件準備好,但和錯誤uccurred和我的螢火蟲抓住它:

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

謝謝,阿里

+0

如何爲我的問題分配賞金! –

回答

2

,請返回爲一個字符串。

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

我發佈了它,我在本地計算機上工作,等待我上傳後檢查它。 –

+0

啊,它沒有工作,鋼鐵發生錯誤,想自己檢查我的網站?看看會發生什麼? –

+1

是的。錯誤仍然是一樣的嗎? – ysrb