Pergunta

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?
Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top