I try this method to get data and also i have try jquery . In jquery i call info method
Hide Copy Code
[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();
}
}
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
jquery
$(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");
}
});
}