Load var into jquery with data coming from DB by Controller

0

The var str has script with fixed values. How do I load these values from a DB through a controller ? I already have the method that brings me this.

   var str = "";
    var data = [];

    $(document).ready(function () {
        $("#btnPesquisarCnpj").click(function () {

            var valor = $("#txtCnpjPesquisa").val();

            if (isCpfCnpj(valor)) {
                return true;

            }
            else {
                $("#txtCnpjPesquisa").focus();

                str += '';
                str += '<label>CNPJ digitado incorretamente!</label>';
                str += '<div>';
                str += '<b><label>Script para Central de Atendimento:</label></b></div>';
                str += '<div><label>Digite novamente o CNPJ, se possível peça que repitam pausadamente.</label>';
                str += '</div>';
                str += '';
                str += '';
                str += '<div>';
                str += '<b>Script para Suporte Técnico:</b></div>';
                str += '<div><label>Digite novamente o CNPJ.</label></div>';

                $('#filtroPesquisa').html(str);

                return false;
            }
        });
    });
    
asked by anonymous 01.05.2014 / 16:22

1 answer

1

In your code there is no ajax call to the server to retrieve the data you want. Basically, you need to make a call via ajax to the server at the URL responsible for retrieving this data. This can be done with jQuery so

var opcoes = {
    type: 'GET',
    dataType: 'json',
    url: 'servidor/caminho-dados'
}

$.ajax(opcoes).then(function (data) {
    // instruções para operar sobre os dados retornados
}).fail(function (jqXHR, textStatus, errorThrown) {
    //instruções para lidar com o erro apresentado
});

You can use this in your code when retrieving data and operating on it. You can read more about using aQuery with jQuery in the jQuery documentation itself here .

    
01.05.2014 / 17:12