使用javascript / AJAX将数据插入MySQL数据库

时间:2022-09-27 16:14:12

I have made a very simple page using google maps API with several fields where users are going to put some data. It looks like following -

我使用谷歌地图API创建了一个非常简单的页面,其中有几个字段,用户将放置一些数据。看起来如下 -

http://aiworker2.usask.ca/marker_field_db.html

http://aiworker2.usask.ca/marker_field_db.html

What I want to do is store the data into MySQL database using javascript/Ajax. I have found several examples that has used Jquery. I'm very new to this javascript/Ajax/Jquery platform. Now my question is-

我想要做的是使用javascript / Ajax将数据存储到MySQL数据库中。我找到了几个使用Jquery的例子。我是这个javascript / Ajax / Jquery平台的新手。现在我的问题是 -

  1. Is it possible to insert data into MySQL database without using JQuery?
  2. 是否可以在不使用JQuery的情况下将数据插入MySQL数据库?
  3. Can anyone send any link of simple example or tutorial to deal with the issue?
  4. 任何人都可以发送任何简单示例或教程的链接来处理问题吗?

Thanks in advance.

提前致谢。

4 个解决方案

#1


3  

Your JavaScript runs on the client (in the browser). Your MySQL database exists on a server.

您的JavaScript在客户端上运行(在浏览器中)。您的MySQL数据库存在于服务器上。

In short, the client-side JavaScript cannot establish a direct connection to MySQL. You need to make an AJAX request to the server which runs a script that interacts with MySQL. The script can be written in any language that has a MySQL library.

简而言之,客户端JavaScript无法建立与MySQL的直接连接。您需要向运行与MySQL交互的脚本的服务器发出AJAX请求。该脚本可以用任何具有MySQL库的语言编写。

Here's an example where an AJAX request is made, which calls a PHP script on the server, which, in turn, grabs data from a MySQL database and returns results back to the client:

这是一个发出AJAX请求的示例,它在服务器上调用PHP脚本,然后从MySQL数据库中获取数据并将结果返回给客户端:

http://www.w3schools.com/PHP/php_ajax_database.asp

http://www.w3schools.com/PHP/php_ajax_database.asp

#2


2  

You can connect to a MySQL database via JavaScript using ActivexObject. Example:

您可以使用ActivexObject通过JavaScript连接到MySQL数据库。例:

var conn = new ActiveXObject("ADODB.Connection");
var connStr = "Provider=SQLOLEDB;Server=mysite;Database=Northwind;User Id=MyId;Password=123aBc";
conn.open(connStr); 

#3


0  

You could send a GET request to a server script with AJAX:

您可以使用AJAX向服务器脚本发送GET请求:

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

#4


0  

Is it possible to insert data into MySQL database without using JQuery?

是否可以在不使用JQuery的情况下将数据插入MySQL数据库?

Yes.
That said, jQuery helps you a lot dealing with Ajax (and cross-browser compatibility), so I would still consider it.

是。也就是说,jQuery可以帮助您处理Ajax(以及跨浏览器兼容性),所以我仍然会考虑它。

Can anyone send any link of simple example or tutorial to deal with the issue?

任何人都可以发送任何简单示例或教程的链接来处理问题吗?

Any Ajax tutorial will do it (e.g. https://developer.mozilla.org/en/AJAX). You just have to learn how to send data to the server side (as POST or GET request). Then it is just PHP and MySQL.

任何Ajax教程都会这样做(例如https://developer.mozilla.org/en/AJAX)。您只需要学习如何将数据发送到服务器端(作为POST或GET请求)。那就是PHP和MySQL。

#1


3  

Your JavaScript runs on the client (in the browser). Your MySQL database exists on a server.

您的JavaScript在客户端上运行(在浏览器中)。您的MySQL数据库存在于服务器上。

In short, the client-side JavaScript cannot establish a direct connection to MySQL. You need to make an AJAX request to the server which runs a script that interacts with MySQL. The script can be written in any language that has a MySQL library.

简而言之,客户端JavaScript无法建立与MySQL的直接连接。您需要向运行与MySQL交互的脚本的服务器发出AJAX请求。该脚本可以用任何具有MySQL库的语言编写。

Here's an example where an AJAX request is made, which calls a PHP script on the server, which, in turn, grabs data from a MySQL database and returns results back to the client:

这是一个发出AJAX请求的示例,它在服务器上调用PHP脚本,然后从MySQL数据库中获取数据并将结果返回给客户端:

http://www.w3schools.com/PHP/php_ajax_database.asp

http://www.w3schools.com/PHP/php_ajax_database.asp

#2


2  

You can connect to a MySQL database via JavaScript using ActivexObject. Example:

您可以使用ActivexObject通过JavaScript连接到MySQL数据库。例:

var conn = new ActiveXObject("ADODB.Connection");
var connStr = "Provider=SQLOLEDB;Server=mysite;Database=Northwind;User Id=MyId;Password=123aBc";
conn.open(connStr); 

#3


0  

You could send a GET request to a server script with AJAX:

您可以使用AJAX向服务器脚本发送GET请求:

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

#4


0  

Is it possible to insert data into MySQL database without using JQuery?

是否可以在不使用JQuery的情况下将数据插入MySQL数据库?

Yes.
That said, jQuery helps you a lot dealing with Ajax (and cross-browser compatibility), so I would still consider it.

是。也就是说,jQuery可以帮助您处理Ajax(以及跨浏览器兼容性),所以我仍然会考虑它。

Can anyone send any link of simple example or tutorial to deal with the issue?

任何人都可以发送任何简单示例或教程的链接来处理问题吗?

Any Ajax tutorial will do it (e.g. https://developer.mozilla.org/en/AJAX). You just have to learn how to send data to the server side (as POST or GET request). Then it is just PHP and MySQL.

任何Ajax教程都会这样做(例如https://developer.mozilla.org/en/AJAX)。您只需要学习如何将数据发送到服务器端(作为POST或GET请求)。那就是PHP和MySQL。