locked
Call ID in jquery RRS feed

  • Question

  • User639567535 posted

    I try this method to get data and also i have try jquery . In jquery i call info method

      [WebMethod]
    public static string info(string id) {
     try {
      string result = "";
    
      Entities er = new Entities();
      List < sp_web_Result > sv = er.sp_web(id).ToList();
      DataTable dt = new DataTable();
      dt.Columns.Add("No", typeof(string));
      dt.Columns.Add("Latitude", typeof(float));
      dt.Columns.Add("Longitude", typeof(float));
    
    
      foreach(var c in sv) {
       dt.Rows.Add(c.No, c.Longitude, c.Latitude);
      };
      result = DataSetToJSON(dt);
      return result;
     } 
     catch (Exception ex) {
      throw new Exception();
     }
    }

    jquery

        <script type="text/javascript">
            $(function () {
    
    
                    var obj = {};
    
                    getdata(obj);
                    return false;
    
            });
    
            function getdata(obj) {
                var RegNo = '';
                var Status = '';
                var latit = '';
                var longi = '';
                $.ajax({
                    type: "POST",
                    url: "home.aspx/info",
                    contentType: "application/json;charset=utf-8",
    
                   data: "{'id':'442'}",
                    datatype: "json",
                    async: true,
                    cache: false,
                    success: function (result) {
                       //map code
    
    
                    },
                    error: function (error) {
                        alert(error);
                        alert("error");
                    }
                });
            }
    
    
    </script>

    in jquery there is line data: "{'id':'442'}", now i want to pass id through web method in this line i hard code id but i want id through web method how to save id and call id in this line

    Thursday, September 22, 2016 9:25 AM

Answers

  • User1213248666 posted

    Hi Bakhtawar,

    Use hidden value for id and get the value using val() and pass it to the data

    @Html.HiddenFor(m => m.ID)
    
    var ID = $("#ID").val();
    data:{id:ID}
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 22, 2016 11:46 PM