ASP.NET上的C#DataTable和JavaScript之间的连接 [英] Connection between C# DataTable and JavaScript on ASP.NET

查看:50
本文介绍了ASP.NET上的C#DataTable和JavaScript之间的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在google-map脚本中定义了一个变量location:

I am defining a variable "location" in my google-map script as :

var location=new google.maps.LatLng(45,65)



对于这个变量,我想从数据库中获取两个坐标。有什么方法可以做到这一点?我正在使用C#访问数据库我的连接字符串是正确的,我将数据提取到dataTable。

问题是如何连接Javascript变量location和dataTable


For this variable I wants to get the two coordinates from database. What are the ways to do this? I'm accessing the database using C# my connection strings are correct, I am fetching the data into dataTable.
The problem is how to connect Javascript variable "location" and dataTable

推荐答案

使用jQuery对你的C#方法进行ajax调用。 br />
Make a ajax call to your C# method using jQuery.
[WebMethod]
public string GetLocation(string location)
{
    // do something with location...
    return "location saved";
}




var location=new google.maps.LatLng(45,65)


.ajax({
type: GET
url: PageName.aspx / GetLocation
数据: location
contentType: application / json; charset = utf-8
dataType: json
成功: function (响应){
alert(response);
}
});
.ajax({ type: "GET", url: "PageName.aspx/GetLocation", data: location, contentType: "application/json; charset=utf-8", dataType: "json", success: function(response) { alert(response); } });





-KR



-KR


这篇关于ASP.NET上的C#DataTable和JavaScript之间的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆