WebService Read Script

0

I'mtryingtomakethiscodework,butintheexcerpt:

success:function(retorno){If(retorno[0].erro){$("h2").html(retorno[0].erro);
                   }                

An error is occurring, and I can not identify what is missing. The message the debuge displays is

  

Uncaught SyntaxError: Unexpected token {

  • // Capturing Data from the Database

    function carregarItens(){    
    var itens = "", url = "../dados/dados.php";       
               //Captura Dados Usando Método AJAX do jQuery
               $.ajax({
               url: url, // url que puxa os dados
                       cache: false, // para os dados nao ficaram em cache
                       type :'GET',
                       dataType: "json", // Fundamental para ler como objeto compartilhado, e nao como um texto ou html comum
                       beforeSend: function() {
                       $("h2").html("Carregando..."); // Mostra informacao carregando
                       },
    
                       error: function() {
                       $("h2").html("Há um problema com a fonte de dados.");
                       },
    
                       success: function(retorno) {
                       If(retorno[0].erro){
                           $("h2").html(retorno[0].erro);
                       }                
                       else{
                       // laço para criar linhas da tabela
                       for (var i = 0; i < retorno.length; i++){
                       itens += "<tr>";
                               itens += "<td>" + retorno[i].id_cliente + "</td>";
                               itens += "<td>" + retorno[i].ds_cliente + "</td>";
                               itens += "<td>" + retorno[i].exercicio_vigente + "</td>";
                               itens += "<td>" + retorno[i].cnpj + "</td>";
                               itens += "</tr>";
                       }
                       //Preenchendo Tabela
                       $("$minhaTabela tbody").html(itens);
                               //Limpando Status Carregando
                               $("h2").html("Carregado");
                       }
                       }              
    
               });
               }
    
  • asked by anonymous 16.01.2018 / 19:13

    1 answer

    -1

    The if of the snippet that captures the data in the database, has an uppercase "i", including the code area of the stack identifies the If as a class.

        
    16.01.2018 / 20:56