连接javascript访问数据库
Connect javascript to access database
你想知道如果我可以连接我的网站在javascript访问数据库,如果我可以我怎么能做到这一点?这是代码:
<!DOCTYPE html>
<html>
<!--Here you will create a polygon by tools that Google maps "drawingManager" gives to you and then you have an array named "coordinates" as an output. This array saves all latLng of the polygon. When you edit the polygon it also edit this variable too.
!-->
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=drawing"></script>
<!--Global variables!-->
<script>
//This variable gets all coordinates of polygone and save them. Finally you should use this array because it contains all latitude and longitude coordinates of polygon.
var coordinates = [];
//This variable saves polygon.
var polygons = [];
</script>
<script>
//This function save latitude and longitude to the polygons[] variable after we call it.
function save_coordinates_to_array(polygon)
{
//Save polygon to 'polygons[]' array to get its coordinate.
polygons.push(polygon);
//This variable gets all bounds of polygon.
var polygonBounds = polygon.getPath();
for(var i = 0 ; i < polygonBounds.length ; i++)
{
coordinates.push(polygonBounds.getAt(i).lat(), polygonBounds.getAt(i).lng());
alert(i);
}
}
</script>
<script>
function initialize()
{
//Create a Google maps.
var map = new google.maps.Map(document.getElementById('map'),
{zoom: 12,
center: new google.maps.LatLng(32.344, 51.048)});
//Create a drawing manager panel that lets you select polygon, polyline, circle, rectangle or etc and then draw it.
var drawingManager = new google.maps.drawing.DrawingManager();
drawingManager.setMap(map);
//This event fires when creation of polygon is completed by user.
google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {
//This line make it possible to edit polygon you have drawed.
polygon.setEditable(true);
//Call function to pass polygon as parameter to save its coordinated to an array.
save_coordinates_to_array(polygon);
//This event is inside 'polygoncomplete' and fires when you edit the polygon by moving one of its anchors.
google.maps.event.addListener(polygon.getPath(), 'set_at', function () {
alert('changed');
save_coordinates_to_array(polygon);
});
//This event is inside 'polygoncomplete' too and fires when you edit the polygon by moving on one of its anchors.
google.maps.event.addListener(polygon.getPath(), 'insert_at', function () {
alert('also changed');
save_coordinates_to_array(polygon);
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:AccessDataSource id="AccessDataSource1" runat="server">
</asp:AccessDataSource>
<asp:AccessDataSource id="AccessDataSource2" runat="server">
</asp:AccessDataSource>
<div id="map" style="width:1024px; height:768px;">
</div>
</form>
</body>
</html>
我想做的是将坐标保存在数据库中,并从数据库中获取坐标。这可能吗?
可能有人想出了一种方法,但在我看来,这是一个非常糟糕的主意。你会暴露你的数据库连接信息给任何人谁可以访问你的javascript(假设它是一个典型的网站),这是…每一个人。这为各种黑客敞开了大门。
最常见的方法是使用某种服务器端语言,如c#/VB。. NET或php(尽管还有很多其他的)。你的Javascript用ajax调用服务器端,你的服务器端代码连接到数据库并返回一个响应
相关文章:
- 从Chrome扩展访问Google Cloud SQL数据库
- 如何在本地存储(或其他数据库)上安全地保存敏感访问代码
- 如何访问日期并将其插入数据库?节点.JS&MongoDB
- 按顺序进行远程数据库访问
- 尝试使用javascript连接访问数据库
- 如何从javascript访问sqlite3数据库表值
- 如何访问Chrome创建的SQLITE数据库
- 音差.无法访问远程 mysql 数据库
- 两个服务器可以访问一个公共的mongoDB数据库吗?
- 如何使用一个代码库在线和离线访问 HTML5/JS 应用程序中的数据库
- 如何从javascript访问MySql数据库的数据
- 电影数据库“访问控制允许来源”问题
- 为登录/注册模式实现正确的php数据库访问
- 格式化从数据库访问的数据
- 使用Node.JS和TypeScript进行强类型数据库访问
- 同步与异步数据库访问
- jQuery -数据库访问失败后的更新按钮图标
- 哪个更糟?一个数据库访问或一个过时的值
- Node.js数据库访问阻塞了主线程
- 数据库访问最佳实践指南