ajax asp后台获取不到post数据,jQuery AJAX调用将数据发布到ASP.Net页面(不是Get但POST)...

选项1.保持服务器端代码相同

首先删除kendo.stringify。然后删除contentType或将其更改为…

"application/x-www-form-urlencoded; charset=utf-8"

…或者将$ .ajax调用更改为:

$.post('DocSummaryDataAsync.aspx',{ vendorId: supplierId,requestType: 'TotalCount' },function (data) { });

选项2.将POST更改为GET

喜欢这个

$.ajax({

async: true,type: "GET",etc.

这将通过QueryString传递您的数据。如果你删除kendo.stringify调用,你将访问所有这样的值:

string vendorId = Request.QueryString[0];

string businessUnit = Request.QueryString[1];

etc.

选项3.使用原来的$ .ajax调用

如果您使用原来的$ .ajax,则适用以下条件:

Request.Params获得“QueryString,Form,Cookies和ServerVariables项目的组合集合”。 – this link

你不和任何人一起工作。相反,您需要访问Request.InputStream。

您可以这样做:

在服务器端创建映射到所请求的JSON对象的类,例如

public class MyClass

{

// The type (int or string) should probably correspond to the JSON

public int vendorId { get; set; }

public string businessUnit { get; set; }

public string productSegmentId { get; set; }

public string programId { get; set; }

public string productManagerId { get; set; }

public string companyIds { get; set; }

public string expired { get; set; }

public string requestType { get; set; }

}

将Request.InputStream转换为该类型,然后可以使用它。

public void ProcessRequest()

{

System.IO.Stream body = Request.InputStream;

System.Text.Encoding encoding = Request.ContentEncoding;

System.IO.StreamReader reader = new System.IO.StreamReader(body,encoding);

string json = reader.ReadToEnd();

JavaScriptSerializer serializer = new JavaScriptSerializer();

MyClass myclass = (MyClass)serializer.Deserialize(json,typeof(MyClass));

int vendorId = myclass.vendorId;

string requestType = myclass.requestType;

// etc...

}

protected void Page_Load(object sender,EventArgs e)

{

ProcessRequest();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值