如何在代码隐藏上调用 json 数据

How to call json data on code behind

本文关键字:调用 json 数据 隐藏 代码      更新时间:2023-09-26
<script type="text/javascript" language="javascript">
        $(document).ready(function () {
            var LastRecID = 1;
            $(window).scroll(function () {
                if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                    var ImpData = document.getElementById('<%= hdnLanguage.ClientID %>').value;
                    if (LastRecID <= 1)
                        sendData();
                    LastRecID++;
                }
            });
            function sendData() {
                $.ajax(
                 {
                     type: "POST",
                     url: "try.aspx/GetData",
                     data: ImpData ,
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     async: "true",
                     cache: "true",
                     success: function (msg) {
                         $("#myDiv").append(msg.d);
                     },
                     Error: function (x, e) {
                         alert("err");
                     }
                 });
            }
        });

    </script>

我有隐藏的字段,它具有相同的价值。我为 hdnLanguage 设置 ImpData

 var ImpData = document.getElementById('<%= hdnLanguage.ClientID %>').value;

我用 Json 发送数据:

data: ImpData 

但是我不知道如何在代码隐藏(在静态 Web 服务中)调用这些数据 (ImpData)。谢谢你的回答。

data将转换为GetData参数。如果您发送这样的data

data: { param1: ImpData }

GetData方法必须至少具有 param1 参数:

public static void GetData(string param1)

我找到答案

杰森:

data: "{'Param': '" + Param + "'}"

代码隐藏:

public static string GetData(string Param)
{
....
}