当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

WebServies返回的XML变成乱

  public List<Data> GetDataList(int count)

  {

  List<Data> data = new List<Data>();

  for (int i = 0; i < count; i++)

  {

  data.Add(new Data

  {

  TopID=i,

  UserID=i*10,

  Img = "Image/me.jpg?http://www.xvna.com",

  Name = "姓名" + i.ToString(),

  content = "中草药虐待虽则上台阶开工字斟句酌",

  Time = DateTime.Now.AddDays(1).ToString()

  });

  }

  return data;

  }

  [WebMethod]

  public string GetJsonData(int count)

  {

  List<Data> data = this.GetDataList(count);

  return JsonHelper.ToJson(data);

  }

  [WebMethod]

  public string GetXmlData(int count)

  {

  List<Data> data = this.GetDataList(count);

  XElement xmlData = new XElement("Root");

  foreach (Data item in data)

  {

  XElement ele = new XElement(

  new XElement("Info",

  new XElement("Img", item.Img),

  new XElement("Name", item.Name),

  new XElement("Content", item.content),

  new XElement("Time", item.Time)

  ));

  xmlData.Add(ele);

  }

  return xmlData.ToString();

  }

  代码

  function GetDataFromServices() {

  $.ajax({

  type: "POST",

  url: "MyWebService.asmx/GetXmlData",

  data: { count: 5 },

  dataType: "text/xml",

  success: function(data) {

  alert(data);

  },

  error: function(msg) { alert(msg); }

  });

  }

  为什么WebServies返回的XML变成乱码?

相关内容
赞助商链接