0

我有一种情况,我需要获取记录总数才能计算页数。

至于现在我将“总记录”存储在 asp:label 控件中。

所以,我想如何在没有 asp:label 控件的情况下读取/获取“总记录”的值。

这是我的代码

$(document).ready(function () {

    //
    GetTotalRecord();

});


function GetTotalRecord() 
{

    $.ajax(
    {
        type: "POST",
        url: "../ws/service.asmx/TotalRecord",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: CalculateTotalRecord,
        error: OnErrorCall
    });

}


function CalculateTotalRecord(xml) 
{
    $('#<%=lblOutput.ClientID%>').html(xml.d);


    //alert($('#<%=lblOutput.ClientID%>').text() );

    v_page_max = Math.ceil ($('#<%=lblOutput.ClientID%>').text() / v_page_size) ;
}
4

1 回答 1

0
  1. 确保您的 URL 对于该服务是正确的
  2. 验证您的服务是否返回 JSON
  3. 了解您的 JSON 对象并阅读正确的属性

    function GetTotalRecord() 
        {
            $.ajax(
            {
                type: "GET", // should be a get 
                url: "../ws/service.asmx/TotalRecord", // Confirm if this URL is right?
                //data: "{}", // not required if you dont have parameters
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data){
                    // if in case your service is returning JSON as string 
                    // then you will have to parse the string to JSON
                    // var result = JSON.Parse(data);
                    //Now read from result
                    //alert(data.d);
                    $('label').html(data.d);
                },
                error: OnErrorCall
            });
        }
    
于 2013-04-18T23:38:27.027 回答