打印本文 打印本文  关闭窗口 关闭窗口  
C++技巧:JS中对象转到c#对象方法
作者:佚名  文章来源:不详  点击数  更新时间:2008/10/22 21:33:36  文章录入:杜斌  责任编辑:杜斌

  <script type="text/javascript">
  var xmlHttp;
  function createXMLHttpRequest()
  {
  if (window.ActiveXObject)
  {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest)
  {
  xmlHttp = new XMLHttpRequest();
  }
  }
  //[{Name:"张可",Class:4},{Name:"李贵",Class:5}]
  function doJSON()
  {
  createXMLHttpRequest();
  xmlHttp.onreadystatechange=handleStateChange;
  xmlHttp.open("post","dojson.aspx",true);
  xmlHttp.setRequestHeader("content-type","application/x-www-form-urlencode");
  xmlHttp.send({Name:"张可",Class:4},{Name:"李贵",Class:5});
  }
  function handleStateChange()
  {
  if(xmlHttp.readyState == 4)
  {
  if(xmlHttp.status == 200)
  {
  alert("is ok!!!");
  }
  }
  }
  </script>
  c#
  protected void Page_Load(object sender, EventArgs e)
  {
  byte[] b = new byte[this.Request.InputStream.Length];
  this.Request.InputStream.Read(b, 0, b.Length);
  string s = System.Text.Encoding.Default.GetString(b);
  student s1 = (student)JavaScriptConvert.DeserializeObject(s, typeof(student));
  }
  public class student
  {
  public string Name
  {
  get{;}
  set{;}
  }
  public string Class
  {
  get{;}
  set{;}
  }
  };
  所需要组件下载http://james.newtonking.com/ 考试大等级站收集整理!
打印本文 打印本文  关闭窗口 关闭窗口