Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WebMethod和jQuery中访问公共变量_C#_Jquery_Asp.net_Webmethod - Fatal编程技术网

C# 在WebMethod和jQuery中访问公共变量

C# 在WebMethod和jQuery中访问公共变量,c#,jquery,asp.net,webmethod,C#,Jquery,Asp.net,Webmethod,在我的ASP.Net页面中,我在使用jQueryAjax滚动时从服务器加载数据。我之所以使用这种方法,是因为使用AJAX从服务器加载数据将有助于任何应用程序提高其性能,因为仅在屏幕上显示的数据是第一次加载的,如果需要,将在用户滚动时从服务器加载更多数据。我正在使用以下代码: $(document).ready( function () { $contentLoadTriggered = false; $(window).scrol

在我的ASP.Net页面中,我在使用jQueryAjax滚动时从服务器加载数据。我之所以使用这种方法,是因为使用AJAX从服务器加载数据将有助于任何应用程序提高其性能,因为仅在屏幕上显示的数据是第一次加载的,如果需要,将在用户滚动时从服务器加载更多数据。我正在使用以下代码:

$(document).ready(

        function () {
            $contentLoadTriggered = false;
            $(window).scroll(

            function () {
                if ($(window).scrollTop() >= ($("#wrapperDiv").height() - $(window).height()) && $contentLoadTriggered == false) { //here I want to check for the isReady variable in ViewState
                    $contentLoadTriggered = true;
                    $.ajax({
                        type: "POST",
                        url: "MyPage.aspx/GetDataFromServer",
                        data: "{}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function (msg) {
                            $("#wrapperDiv").append(msg.d);
                            $contentLoadTriggered = false;
                        },
                        error: function (x, e) {
                            alert("The call to the server side failed. " + x.responseText);
                        }
                    });
                }
            });
        });

[WebMethod]
公共静态字符串GetDataFromServer()
{
string resp=string.Empty;

对于(inti=1;i我能想到的最好方法是发送自定义类对象或字符串[]

Public class CustomClass
{
    public string HTML { get; set; }
    public bool Load  { get; set; }
}

[WebMethod()]
public static StatusViewModel  GetDataFromServer()
{
    // do work
    return CustomObject;
}

希望有帮助。

我能想到的最好的方法是发送自定义类对象或字符串[]

Public class CustomClass
{
    public string HTML { get; set; }
    public bool Load  { get; set; }
}

[WebMethod()]
public static StatusViewModel  GetDataFromServer()
{
    // do work
    return CustomObject;
}

希望有帮助。

+1;我将使用
字符串[]
,并将其传递给jQuery。您知道如何从jQuery访问ViewState吗?恐怕不知道,我不知道,但您可以点击此链接。我不知道这是否是一个好的做法,但我使用了一个隐藏字段。感谢您的帮助+1;我将使用
字符串[]
,并将其传递给jQuery。您知道如何从jQuery访问ViewState吗?恐怕不知道,但您可以访问此链接。我不知道这是否是一个好的做法,但我使用了一个隐藏字段。谢谢您的帮助