scropio gurl

scropio gurl

  • NA
  • 147
  • 96.5k

Call ID in jquery

Sep 22 2016 6:10 AM
I try this method to get data and also i have try jquery . In jquery i call info method
  1. [WebMethod]  
  2. public static string info(string id) {  
  3.  try {  
  4.   string result = "";  
  5.   
  6.   Entities er = new Entities();  
  7.   List < sp_web_Result > sv = er.sp_web(id).ToList();  
  8.   DataTable dt = new DataTable();  
  9.   dt.Columns.Add("No", typeof(string));  
  10.   dt.Columns.Add("Latitude", typeof(float));  
  11.   dt.Columns.Add("Longitude", typeof(float));  
  12.   
  13.   
  14.   foreach(var c in sv) {  
  15.    dt.Rows.Add(c.No, c.Longitude, c.Latitude);  
  16.   };  
  17.   HttpContext.Current.Session["ID"] = id;  
  18.   result = DataSetToJSON(dt);  
  19.   return result;  
  20.  }   
  21.  catch (Exception ex) {  
  22.   throw new Exception();  
  23.  }  
  24. }  
jquery
 
  1.  <script type="text/javascript">  
  2.         $(function () {  
  3.   
  4.             var RegNo = '';  
  5.             var Status = '';  
  6.             var latit = '';  
  7.             var longi = '';  
  8.           var ID = '<%=Session["ID"]%>'.val();  
  9.                  var obj = {};  
  10.                obj.ID=ID;  
  11.                 getdata(obj);  
  12.                 return false;  
  13.   
  14.         });  
  15.   
  16.         function getdata(obj) {  
  17.   
  18.             $.ajax({  
  19.                 type: "POST",  
  20.                 url: "home.aspx/info",  
  21.                 contentType: "application/json;charset=utf-8",  
  22.   
  23.                data: { ID: obj.ID } 
  24.                 datatype: "json",  
  25.                 async: true,  
  26.                 cache: false,  
  27.                 success: function (result) {  
  28.                    //map code  
  29.   
  30.   
  31.                 },  
  32.                 error: function (error) {  
  33.                     alert(error);  
  34.                     alert("error");  
  35.                 }  
  36.             });  
  37.         }  
  38.   
  39.   
  40. </script>  
 

try to pass id through web method in this line data:JSON.stringify(obj.ID),

when i do this there is error on console

Uncaught TypeError: "442".val is not a function

 
when i remove  .val() then this show error 
Failed to load resource: the server responded with a status of 500 (Internal Server Error) 

Answers (3)