【问题标题】:Ajax post jSon data in Request objectAjax 在 Request 对象中发布 JSON 数据
【发布时间】:2019-07-23 12:40:49
【问题描述】:

我正在使用 jQuery 将 json 数据传递给 Ajax 调用。我想在 global.ascx 上的 Application_BeginRequest 函数中读取这个 json 以获得一些目的。 我在哪里可以在“请求”对象中找到这些数据。 我发现 Questystring 和 Form of Request 对象。两者都是空的。

使用jQuery调用ajax函数如下

问候

乌梅什

var inputData = "{'ID':'" + ID + "', 'Code':'" + Centre +"'}";

var pageURL = window.location.protocol + "//" + window.location.host + 
    "/webmethod.aspx/MyFunction"
$.ajax({
    type: "POST",
    url: pageURL,
    data: inputData,
    contentType: "application/json; charset=utf-8",
    dataType: "json",

【问题讨论】:

标签: request http-post asp.net-ajax


【解决方案1】:

P.S -假设您想使用**jquery**json 数据发布到您的ASPX 页面,请在下面添加示例。

function GetEmployee()
    {
        var jsonObj = {"Org":0 ,"Dept":0,"Desg":0,"Grp":0,"SubGrp":0,"Loc":0,"Prv":'CanViewEmployee',"CustAttrId":0,CustAttrVal:"","Status":'1' };
        $.ajax({
            url: 'EmployeeSearchControl.aspx/populateJsonResult',
            datatype: 'json',
            data:JSON.stringify(jsonObj),
            method: 'Post',
            success: function (data) {
                if(data != null || data != "")
                {
                    for(var i=0;i<data.length;i++)
                    {
                        addEmployeeToGrid(data[i]);
                    }
                }
            }
        })
    }


 public class JSONRequest
    {
        public long Org { get; set; }
        public long Dept { get; set; }
        public long Desg{ get; set; }
        public long Grp { get; set; }
        public long SubGrp { get; set; }
        public long Loc { get; set; }
        public long Cat { get; set; }
        public string Prv { get; set; }
        public long CustAttrId { get; set; }
        public string CustAttrVal { get; set; }
        public string Status { get; set; }
    }
protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "application/json";
            string ap = Request["org"];
            HttpContext.Current.Request.InputStream.Position = 0;
            string jsonString = "";
            using (StreamReader inputStream = new StreamReader(this.Request.InputStream))
            {
                jsonString = inputStream.ReadToEnd();
            }
            JSONRequest masterDetails = Newtonsoft.Json.JsonConvert.DeserializeObject<JSONRequest>(jsonString);
}

希望对您有所帮助。如果您需要任何其他帮助,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 2014-12-08
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多