从严格的HTML和JavaScript网站访问数据库的最佳方法是什么?

时间:2021-07-07 22:47:19

We are creating a website, and we are currently only using HTML5 and javascript. We need to be able to both read from and write to a database. We are using a postgressql database. What is your recommendation on how to go about querying the database? We are open to using other languages with our HTML and javascript to make this happen.

我们正在创建一个网站,目前我们只使用HTML5和javascript。我们需要能够读取和写入数据库。我们正在使用postgressql数据库。您对如何查询数据库的建议是什么?我们愿意使用其他语言和我们的HTML和JavaScript来实现这一目标。

6 个解决方案

#1


2  

Use some server-side language. PHP, Ruby, Python would suffice.

使用一些服务器端语言。 PHP,Ruby,Python就足够了。

Then it depends on how you want your UI to behave - you can either use POST/GET regular requests, or use ajax (asynchronous) requests.

然后,它取决于您希望UI的行为方式 - 您可以使用POST / GET常规请求,也可以使用ajax(异步)请求。

HTML and Javascript are client-side technologies, and your sql server is on the server side. It is just not meant to work with a direct communication.

HTML和Javascript是客户端技术,您的SQL服务器位于服务器端。它并不意味着与直接沟通合作。

Even if there is some way to do this directly without any server-side language, (not that I'm aware of such), it would mean you'll have your database credentials on the client. And so anyone will be free to execute whatever queries he likes.

即使有一些方法可以在没有任何服务器端语言的情况下直接执行此操作(不是我意识到这一点),这意味着您将在客户端上拥有数据库凭据。所以任何人都可以*地执行他喜欢的任何查询。

#2


1  

If you can use javascript, you can use AJAX... You can setup a server that processes all AJAX calls and connects to the database itself.

如果你可以使用javascript,你可以使用AJAX ...你可以设置一个处理所有AJAX调用并连接到数据库本身的服务器。

#3


0  

For security reasons you will have to access the database on the server before moving the data to the client. This rules out any javascript, unless you have a readonly account for the database. For that reason I would advice you to go with a language like PHP, Java Tomcat or ASP.NET.

出于安全原因,在将数据移动到客户端之前,您必须访问服务器上的数据库。这排除了任何javascript,除非您拥有数据库的只读帐户。出于这个原因,我建议你使用PHP,Java Tomcat或ASP.NET等语言。

#4


0  

If the requirements are indeed that "we can only use HTML/JavaScript" and "we need to access a database" then you have a couple of approaches, but they may not be the actual right approaches for you.

如果要求确实是“我们只能使用HTML / JavaScript”和“我们需要访问数据库”,那么您有几种方法,但它们可能不适合您。

  1. CouchDB (not PostgreSQL) is very JSON-friendly and is a database. It can sit on the web server and be accessed directly from your JavaScript easily. However, there is a major security risk here. Anyone will have access to your database. Depending on what the data is, it can be secured in various ways. But it's still a huge risk.
  2. CouchDB(不是PostgreSQL)非常适合JSON,是一个数据库。它可以位于Web服务器上,可以直接从JavaScript轻松访问。但是,这里存在重大的安全风险。任何人都可以访问您的数据库。根据数据的不同,可以通过各种方式对其进行保护。但它仍然是一个巨大的风险。

  3. Server-side JavaScript. Look into node.js to run on the web server that's hosting the database. Some pretty great projects have been based on that recently and "accessing a database" by itself should be pretty easy.
  4. 服务器端JavaScript。查看node.js以在托管数据库的Web服务器上运行。最近一些相当不错的项目基于此,并且“访问数据库”本身应该非常简单。

However, in normal day-to-day work, I'm going to have to agree with the other answers so far. Use a server-side programming environment to handle the database stuff. Unless your software actually fits into my suggestions above, in which case that's pretty awesome and go for it.

但是,在正常的日常工作中,到目前为止,我将不得不同意其他答案。使用服务器端编程环境来处理数据库内容。除非你的软件实际上符合我上面的建议,在这种情况下,这非常棒,并为此而努力。

#5


0  

Lots of options, I'd suggest looking at DWR. It enables server side java objects to be invoked from javascript clients.

有很多选择,我建议看一下DWR。它允许从javascript客户端调用服务器端Java对象。

#6


0  

The best way is to use a scripting language, like PHP, Ruby, Python, Perl, etc.

最好的方法是使用脚本语言,如PHP,Ruby,Python,Perl等。

#1


2  

Use some server-side language. PHP, Ruby, Python would suffice.

使用一些服务器端语言。 PHP,Ruby,Python就足够了。

Then it depends on how you want your UI to behave - you can either use POST/GET regular requests, or use ajax (asynchronous) requests.

然后,它取决于您希望UI的行为方式 - 您可以使用POST / GET常规请求,也可以使用ajax(异步)请求。

HTML and Javascript are client-side technologies, and your sql server is on the server side. It is just not meant to work with a direct communication.

HTML和Javascript是客户端技术,您的SQL服务器位于服务器端。它并不意味着与直接沟通合作。

Even if there is some way to do this directly without any server-side language, (not that I'm aware of such), it would mean you'll have your database credentials on the client. And so anyone will be free to execute whatever queries he likes.

即使有一些方法可以在没有任何服务器端语言的情况下直接执行此操作(不是我意识到这一点),这意味着您将在客户端上拥有数据库凭据。所以任何人都可以*地执行他喜欢的任何查询。

#2


1  

If you can use javascript, you can use AJAX... You can setup a server that processes all AJAX calls and connects to the database itself.

如果你可以使用javascript,你可以使用AJAX ...你可以设置一个处理所有AJAX调用并连接到数据库本身的服务器。

#3


0  

For security reasons you will have to access the database on the server before moving the data to the client. This rules out any javascript, unless you have a readonly account for the database. For that reason I would advice you to go with a language like PHP, Java Tomcat or ASP.NET.

出于安全原因,在将数据移动到客户端之前,您必须访问服务器上的数据库。这排除了任何javascript,除非您拥有数据库的只读帐户。出于这个原因,我建议你使用PHP,Java Tomcat或ASP.NET等语言。

#4


0  

If the requirements are indeed that "we can only use HTML/JavaScript" and "we need to access a database" then you have a couple of approaches, but they may not be the actual right approaches for you.

如果要求确实是“我们只能使用HTML / JavaScript”和“我们需要访问数据库”,那么您有几种方法,但它们可能不适合您。

  1. CouchDB (not PostgreSQL) is very JSON-friendly and is a database. It can sit on the web server and be accessed directly from your JavaScript easily. However, there is a major security risk here. Anyone will have access to your database. Depending on what the data is, it can be secured in various ways. But it's still a huge risk.
  2. CouchDB(不是PostgreSQL)非常适合JSON,是一个数据库。它可以位于Web服务器上,可以直接从JavaScript轻松访问。但是,这里存在重大的安全风险。任何人都可以访问您的数据库。根据数据的不同,可以通过各种方式对其进行保护。但它仍然是一个巨大的风险。

  3. Server-side JavaScript. Look into node.js to run on the web server that's hosting the database. Some pretty great projects have been based on that recently and "accessing a database" by itself should be pretty easy.
  4. 服务器端JavaScript。查看node.js以在托管数据库的Web服务器上运行。最近一些相当不错的项目基于此,并且“访问数据库”本身应该非常简单。

However, in normal day-to-day work, I'm going to have to agree with the other answers so far. Use a server-side programming environment to handle the database stuff. Unless your software actually fits into my suggestions above, in which case that's pretty awesome and go for it.

但是,在正常的日常工作中,到目前为止,我将不得不同意其他答案。使用服务器端编程环境来处理数据库内容。除非你的软件实际上符合我上面的建议,在这种情况下,这非常棒,并为此而努力。

#5


0  

Lots of options, I'd suggest looking at DWR. It enables server side java objects to be invoked from javascript clients.

有很多选择,我建议看一下DWR。它允许从javascript客户端调用服务器端Java对象。

#6


0  

The best way is to use a scripting language, like PHP, Ruby, Python, Perl, etc.

最好的方法是使用脚本语言,如PHP,Ruby,Python,Perl等。