类型:JQuery;问题:ajax调用ashx文件;结果:ashx文件怎么获取$.ajax()方法发送的json数据

ashx文件怎么获取$.ajax()方法发送的json数据

作者:careful 和ajax相关  
 
$.ajax({
  type: "POST",
  url: "handler.ashx",
  data: "{name:'jack'}",
  dataType:"json",
  contentType:"application/json",
  success: function(msg){ alert( "Data Saved: " + msg.name ); } 
  }); 
在handler.ashx文件中用
string name = context.Request.Params["name"];
context.Response.ContentType = "application/json";
HttpContext.Current.Response.Write("{name:'" + name + "'}");
不行获取不到数据
alert 显示的时候msg.name为空
------回答---------

------其他回答---------

既然是post提交的,try
C# code
string name = context.Request.Form["name"];
------其他回答---------

post方式提交的是使用 context.Request.Form 获取数据
获取不到的原因也有可能是你的url路径不对 设断点断下 看看能不能跳到这个handler.ashx就知道了
------其他回答---------

C# code
string name = context.Request.Params["name"].ToString(); context.Response.Write("结果:" + name);
------其他回答---------

这个问题我也遇到了.你在获取数据时应该这样:
string items = Request["items"];

“ashx文件怎么获取$.ajax()方法发送的json数据”的更多相关文章 》

原文地址:https://www.cnblogs.com/longphui/p/5073485.html