I would like to update my webpage with data that is contained inside the database without reloading the web page. So I was wondering :

  • How should I do it?
  • Could I query the database using javascript?
  • Is there any security risk?
有帮助吗?

解决方案

You should look into AJAX. However, you cannot render an entire page with it.

其他提示

You can't and you shouldn't be able to query the database with JavaScript. That would mean your database was exposed without any intermediary to guard it. Bad idea.

You can make an Ajax call to a service that could query the database on your behalf and return the values. You can update the DOM without reloading the page that way.

The service can validate and bind the request, making sure you don't have any SQL injection attacks. It should require credentials to access. It ought to use HTTPS as the wire protocol. Nice and safe that way.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top