Select in the database, only with jQuery

Asked

Viewed 506 times

0

How do I make a select in the database using only a jQuery? I have two combobox and want to use their value to make a select in my database:

        $.getJSON('/MinhaDoenca/rest/hospital/get', function(data) {

            for ( var index in data) {

                $("#idHospital").append(
                        '<option value="'+data[index].nome+'">'
                                + data[index].nome + '</option>')
            }

        });

        $.getJSON('/MinhaDoenca/rest/especialidade/get', function(data) {

            for ( var index in data) {

                $("#idEspecialidade").append(
                        '<option value="'+data[index].descricao+'">'
                                + data[index].descricao + '</option>')
            }

        });

I would like to take these two values and make a query in my database, but using only jQuery and HTML, without PHP. Is it possible? Could someone give me an example? (my database is Postegresql)

1 answer

0


It is not possible as jQuery is a library developed in pure Javascrit as you probably should know or should, which is a scripting programming language interpreted by Browser(Browser) on the client side(client-side), where it cannot execute internal commands on the server side(server-side).

So this way you can’t make select commands in your database using only Jquery, because it would also be something of total insecurity for your site. And if that were possible any programmer could access your website by the Browser console is to make select’s, Insert’s, update’s, delete’s etc in your database.

What would be possible would be to create a Rest, Soap, RPC API in a server-side programming link, where with jQuery you would consume it, which by its code is probably what you want to do.

If you want to create a Web Service where you would only consume it with jQuery you could use the PHP slimframework framework, if it is PHP you are using, here is a very simple example of using it:

<?php
$app = new \Slim\Slim();
$app->get('/MinhaDoenca/rest/hospital/get', function() {

  //Seu código para acessar o banco de dados

});
$app->run();

Note: But this is even possible to be you use Node.js which is a platform built on the Javascript engine of Google Chrome that runs on the server side like PHP, Java, Python etc, not seen here.

  • Even consuming a Web Service?

  • When I said API I refer to this API Rest, Soap etc, which are ways to be developing Web Service’s.

  • That also using a Web Service would not run away from a server-side programming link like PHP.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.