Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
 }
}


What I have tried:

jquery

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) {
                    alert("map2");
                    $("#tabledata").empty();
                    var table_data = JSON.parse(result.d).response;
                    console.log(JSON.parse(result.d));
                    $("#tabledata").empty();
                    if (table_data.length > 0) {
                        $("#tabledata").append(
      "NoLongitudeLatitude");

                        for (var i = 0; i < table_data.length; i++) {
                            if (table_data[i] !== null) {
                                $("#tabledata").append("" +
                               table_data[i][0] + " " +
                               table_data[i][1] + " " +
                               table_data[i][2] + " 
");

                                No = table_data[i][0];
                                latit = table_data[i][2];
                                longi = table_data[i][1];
                            }
                        }
                    }
                    else {
                        $("#tabledata").hide();
                    }

                    var map;
                    //var markers;
                    debugger;
                    var latlng = new google.maps.LatLng(24.0895898, 67.0998546);
                    debugger;
                    var myOptions = {
                        zoom: 8,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };
                    debugger;
         map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

                    debugger;


                    for (i = 0; i < table_data.length; i++) {
                        var data = table_data[i]
        var myLatlng = new google.maps.LatLng(table_data[i][2], table_data[i][1]);
                        var marker = new google.maps.Marker({
                            position: myLatlng,
                           map: map,
                           title: 'Click me'
                        });

                        (
                            function (marker, data) {
                            google.maps.event.addListener(marker, "click", function (e) {
                                infoWindow.setContent(RegNo,Status);
                                infoWindow.open(map, marker);

                            });
                        }

                        )
                        (marker, data);

                    }



                },
                error: function (error) {
                    alert(error);
                    alert("error");
                }
            });
        }


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
Posted
Updated 22-Sep-16 4:20am
v3
Comments
Richard Deeming 22-Sep-16 9:20am    
catch (Exception ex) {
  throw new Exception();
}


Well, that's a new one. Not only do you throw away the stack trace, you throw away all information from the exception.

You're not doing anything with the caught exception, so just remove the try..catch block.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900