来自jquery中web方法的调用ID [英] Call ID from web method in jquery
本文介绍了来自jquery中web方法的调用ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试这种方法来获取数据,我也尝试了jquery。在jquery我打电话给info方法
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
What I have tried:
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");
}
});
}
在jquery中有行数据:{'id':'442'},现在我想要通过web方法传递id在这行我硬代码id但我想通过web方法id如何在这行中保存id和调用id
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
推荐答案
( function (){
var obj = {};
getdata(obj);
return false ;
});
function getdata(obj){
var RegNo = < span class =code-string>' ';
var 状态= ' ';
var latit = ' ';
var longi = ' ';
(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:< span class =code-string> json,
async: true ,
cache: false ,
成功: function (result){
aler t( map2);
.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(); var table_data = JSON.parse(result.d).response; console.log(JSON.parse(result.d));
这篇关于来自jquery中web方法的调用ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文