首页 > 代码库 > AJAX请求

AJAX请求

$.ajax({  type:"post",  //请求方式  url:"../../ZCGL/ZCGL_Handler.ashx",   data: {type:ZCGL_NGD_ISCZ,_str:_str},     //参数  async: false,  contentType:"application/x-www-form-urlencoded;charset=UTF-8",  //dataType:"json",    

  success: function (data) {
  if(data != "False")    {       alert("成功!");    } else {      alert("失败!");    };  } });

后台接收:

 string type=context.Request["type"].ToString();

 

json:

    <script src=http://www.mamicode.com/"jquery-1.8.3.js" type="text/javascript"></script>    <script src=http://www.mamicode.com/"json2.js" type="text/javascript"></script>

 

<script type="text/javascript">          var user = {            name: "张三",            age: 25,            weight: 135        };        $(function () {            $.ajax({                url: "AJAX.aspx",                type: "post",                data: JSON.stringify(user),//序列化                headers: { Accept: "application/json", "Content-Type": "application/json" },                dataType: "json",                processData: false,                success: function (data, textStatus, jqXHR) {                }            });        });     </script>

后台:

using Newtonsoft.Json;using System.Web.Services;using Newtonsoft.Json.Linq;

 

StreamReader sr = new StreamReader(Request.InputStream);            string userStr = sr.ReadToEnd();            JObject jo = (JObject)JsonConvert.DeserializeObject(userStr);            JArray jarry = JArray.Parse(jo["User"].ToString());
//var modleList = JsonConvert.DeserializeObject<List<SupplierDetail>>(modle);

 

网上下载文件  

Newtonsoft.Json.Net20.dll

json2.js

引用  Newtonsoft.Json.Net20.dll

 

AJAX请求