You must Sign In to post a response.
  • Category: JQuery

    Access webmethod value using jquery

    Hi ,

    my application contains a webmethod and that webmethod contains an integer value like this

    [WebMethod]
    public static Address[] ViewAddress(string id)
    {

    string msg;
    string id1 = id.Trim();
    BAL objBal = new BAL();
    List<Address> details = new List<Address>();
    DataSet ds = objBal.ViewAddress(id1, out msg);
    int count = ds.Tables[0].Rows.Count;


    }

    my requirement is to retrieve the integer value count using jquery

    How it is possible.

    regards

    Baiju
  • #758103
    you can call any webmethod using jquery as follows
    function ShowCurrentTime() {
    $.ajax({
    type: "POST",
    url: "pagename.aspx/ViewAddress",
    data: '{name: "' + $("#<%=txtCount.ClientID%>")[0].value + '" }',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    failure: function(response) {
    alert(response.count);
    }
    });
    }


    see more details here
    http://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx

    Regards & thanks
    Arvind kumar
    Visit--blog.akumars.esoftera.in

  • #758107
    Hello Baiju,

    Refer the below code:
    <script type="text/javascript" src="script/jquery-1.2.6.min.js"></script>
    <script type="text/javascript">

    $(function() {
    $('#Button1').click(getCount);
    });

    function getCount() {
    $.ajax({
    type: "POST",
    url: "ServiceName.asmx/Count",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) {
    var add = response.d;
    $('#output').empty();
    $.each(add, function(index, Address) {
    $('#output').append(Address.count);
    });
    },
    failure: function(msg) {
    $('#output').text(msg);
    }
    });
    }
    </script>

    Hope it may help you to resolve your problem.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."


  • Sign In to post your comments