Select in database, only with jQuery [duplicate]

0

How do I make a select in the database using only using a jQuery? I have two combobox and I 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. It's possible? Could someone give me an example? (my database is PostegreSQL)

    
asked by anonymous 08.11.2015 / 16:38

1 answer

0

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

So that way you can not make select statements in your database using only JQuery, because it would also be something of total insecurity for your site. And being that it was possible any programmer could access your site through the Browser console is to do select's, insert's, update's, delete's etc in your database.

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

If you are looking to create a Web Service where you would only use it with jQuery you could use the PHP slimframework framework, if this 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 Google Chrome JavaScript engine that runs on the server side like PHP, Java, Python etc, which is not the case here.

    
08.11.2015 / 17:34