.ashx文件代码:
    
[System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
    public DataSet GetSearchTable()
    {
        DataSet ds = new eBest.MQS.BusinessLogic.SearchTableManager().searchTable();
        return ds;
    }
aspx页面代码:
       $(document).ready(function(){
       var trlStr="../Handler/SearchConfig.ashx";
         $.ajax({
                    //async:false,
                    type: "POST",
                    url: trlStr+"/GetSearchTable",
                    contentType: "application/json",
                    data: "{}",
                    dataType: 'xml', //返回的类型为XML
                    success: function(result) {
                            $(result).find("Table").each(function() {
                                $("#scTableId").append("<option value="+ $(this).find("Id").text()+ ">" + $(this).find("Title").text() + "</option>");//给下拉列表select绑定数据
                            });
  
                    },
                    error: function(result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                        if (status == 'error') {
                            alert(result.responseText);
                        }
                    }
                });
});
开始url用的是asmx文件没有问题,但老大说要用ashx文件,我就改了下,结果没有值。不知道哪里出问题了

解决方案 »

  1.   

    用这个试一下,datatable自己就支持序列化的 ds.WriteXml(context.Response.OutputStream);
      

  2.   

    把返回改成 string
    public string GetSearchTable()
     return ds.GetXml();
      

  3.   

    那方法返回的是dataset,应该解析不了吧
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Services;
    using System.Data;
    using System.Data.SqlClient;namespace JqGrid_Demo
    {
        /// <summary>
        /// $codebehindclassname$ 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class GetXMLHandler : IHttpHandler
        {        public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/xml";
                string strSql = "SELECT  iUSERID,sUserName,sQuestion,dtLastLoginTime FROM Sys_Users";            //数据存入一个DATATABLE
                //DataTable dt = SqlServerHelper.Query(strSql).Tables[0];//读取数据
                string sqlConStr = System.Configuration.ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
                DataSet dataSet = new DataSet();
                using (SqlConnection con = new SqlConnection(sqlConStr))
                {
                    con.Open();
                    SqlDataAdapter adapter = new SqlDataAdapter(strSql, con);
                    adapter.Fill(dataSet);                
                }
                context.Response.Write(dataSet.GetXml());
            }        public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
      

  5.   


    XmlTextWriter  writer=new XmlTextWriter  (Response.OutPutStream,Response.ContentEncoding);dt.WriterXml(writer);
    response.ContentType="text/xml";
    Response.Flush();
    Response.End();//前台 jquery解析
    $(msg).find("table").each(function(){
    $(this).find('price').text();
    })