I no longer see the script executed in the browser console

0

I have this code in jquery and I always use the console to see how my application works.

But now it does not take effect on the page and the console does not show the .php script that is inside the ajax requests. I was adding functions and suddenly it happened to me.

var content;
var id;
var nombre;
var marca;
var precio;
var alicuota;
$(document).ready(function() {
listar();
$("#cat").focus();
listarcategorias();
listarsubcategorias();
function filtrarsubcat(idcat){
        var filtrado=[];
        var existe;
//recorro subcategorias
    for(var i = 0; i < subcat.length; i++) {
      //si esta el idcat
    if (subcat[i].idcategoria === idcat){
        //lo meto en el array
        filtrado.push(subcat[i]);}
        
        }
        $("#subcat").empty();
     
        for(var i = 0; i < filtrado.length; i++) {
          
          var newRow ="<option id="+filtrado[i].idsubcat+">"+filtrado[i].subcategoria+"</option>";
                  
          $(newRow).appendTo("#subcat");
        
       
    }
}   
    

function listarsubcategorias(){
   
    $.ajax({
	  
            type: "POST",
            url: "../gestionweb/includes/php/getsubcategorias.php",
          dataType: 'json',
            

            error: function(){
                alert("error petición ajax");
            },
            success: function(data){
      
       subcat=data;
               for (var i = 0; i < data.length; i++) {
                 
                            var newRow ="<option id="+data[i].idsubcat+">"+data[i].subcategoria+"</option>";
                  
                $(newRow).appendTo("#subcat");
                         
                
                       
        
                             
       
    
               
            }
           
        }
});}

$("#cat").change(function(){
    var idcat=$(this).children(":selected").attr("id");
    if (idcat){
       filtrarsubcat(idcat);
       filtrarcat(idcat);
    }
});
function filtrarcat(idcat){
        var filtrado=[];
        var existe;
    for(var i = 0; i < content.length; i++) {
    if (content[i].idcategoria===idcat) {
        filtrado.push(content[i]);
        
       
    }
}
     if (filtrado.length>0) {
        
      $("#resultado tbody").empty();
        
            for (var i = 0; i < filtrado.length; i++) {
          
                var newRow =
                    "<tr>" +
                    "<td>" + filtrado[i].idproducto + "</td>" +
                    "<td>" + filtrado[i].nombre + "</td>" +
                    "<td>" + filtrado[i].marca + "</td>" +
                    "<td>" + filtrado[i].categoria + "</td>" +
                    "<td>" + filtrado[i].subcategoria + "</td>" +
                    "<td>" + filtrado[i].precio + "</td>" +
                     "<td>" + filtrado[i].aliiva + "</td>" +
                    "<td><input type='radio' id='"+filtrado[i].idproducto+"' name='seleccion'/></td>"+
                    "</tr>";
                  
                $(newRow).appendTo("#resultado tbody");                 
       }
 
	
  
}};
$("#subcat").change(function(){
   
    var idsubcat=$(this).children(":selected").attr("id");
    if (idsubcat){
       filtrarprodsubcat(idsubcat);
    
    }
});
function listarcategorias(){
    accion="listadocat";
    $.ajax({
	  
            type: "POST",
            url: "../gestionweb/includes/php/getcategoria.php",
            data: {"accion":accion}, 
            dataType: 'json',

            error: function(){
                alert("error petición ajax");
            },
            success: function(data){
                
       console.log(data);
               for (var i = 0; i < data.length; i++) {
               
        
                var newRow ="<option id="+data[i].idcategoria+">"+data[i].categoria+"</option>";
                  
                $(newRow).appendTo("#cat");                 
       
    
               
            }
           
        }
});}
var nombreBusqueda;

 $("#nombre").keyup(function() {
            
        nombreBusqueda=$("#nombre").val();
        filtrar(nombreBusqueda);
    }
);
  var id;
  var nombre;
  var marca;
  var producto;
    var precio;
// Detectar clic en una fila
$("#resultado tbody").click(function(event) {
  $("tr").click(function(event) {
 id = $(this).find("td:first-child").text();
 nombre = $(this).children('td').eq(1).text();
 marca = $(this).children('td').eq(2).text();
 precio = $(this).children('td').eq(4).text();
 alicuota = $(this).children('td').eq(5).text();
 producto = nombre + "  " +  marca;
$("#nombreselec").val(producto);

});
 

$("#Agregar").click(function(event){
  var cantidad=$("#CANTIDAD").val();
  var nombreart=$("#nombreselec").val();
  if (nombreart===""){
    alert("seleccione un articulo");
 }
  if (cantidad!==""){
    var accion = "agregar";
 
    $.ajax({
	  
            type: "POST",
            url: "../gestionweb/includes/php/procesoFactA.php",
            data: {"accion":accion,"id":id,"cantidad":cantidad,"nombre":nombre,"marca":marca,"precio":precio,"alicuota":alicuota}, 
         

            error: function(){
                alert("error petición ajax");
            },
           
        }).fail( function( jqXHR, textStatus, errorThrown ) {

  if (jqXHR.status === 0) {

    alert('Not connect: Verify Network.');

  } else if (jqXHR.status == 404) {

    alert('Requested page not found [404]');

  } else if (jqXHR.status == 500) {

    alert('Internal Server Error [500].');

  } else if (textStatus === 'parsererror') {

    alert('Requested JSON parse failed.');

  } else if (textStatus === 'timeout') {

    alert('Time out error.');

  } else if (textStatus === 'abort') {

    alert('Ajax request aborted.');

  } else {

    alert('Uncaught Error: ' + jqXHR.responseText);

  }

});

    
  } else{
    alert("ingrese cantidad");
  }
});

});

function filtrarprodsubcat(idsubcat){
        var filtrado=[];
        var existe;
    for(var i = 0; i < content.length; i++) {
    if (content[i].idsubcat===idsubcat) {
        filtrado.push(content[i]);
        
       
    }
}
     if (filtrado.length>0) {
        
      $("#resultado tbody").empty();
        
            for (var i = 0; i < filtrado.length; i++) {
          
                var newRow =
                    "<tr>" +
                    "<td>" + filtrado[i].idproducto + "</td>" +
                    "<td>" + filtrado[i].nombre + "</td>" +
                    "<td>" + filtrado[i].marca + "</td>" +
                    "<td>" + filtrado[i].categoria + "</td>" +
                    "<td>" + filtrado[i].subcategoria + "</td>" +
                    "<td>" + filtrado[i].precio + "</td>" +
                    "<td>" + filtrado[i].aliiva + "</td>" +
                    "<td><input type='radio' id='"+filtrado[i].idproducto+"' name='seleccion'/></td>"+
                    "</tr>";
                  
                $(newRow).appendTo("#resultado tbody");                 
       }
 
	
  
}};
function filtrar(dato){
        var filtrado=[];
        var existe;
    for(var i = 0; i < content.length; i++) {
    if (content[i].nombre.toLowerCase().indexOf(dato.toLowerCase())!=-1) {
        filtrado.push(content[i]);
        
       
    }
}
     if (filtrado.length>0) {
        
      $("#resultado tbody").empty();
        
            for (var i = 0; i < filtrado.length; i++) {
          
                var newRow =
                    "<tr>" +
                    "<td>" + filtrado[i].idproducto + "</td>" +
                    "<td>" + filtrado[i].nombre + "</td>" +
                    "<td>" + filtrado[i].marca + "</td>" +
                    "<td>" + filtrado[i].categoria + "</td>" +
                    "<td>" + filtrado[i].subcategoria + "</td>" +
                    "<td>" + filtrado[i].precio + "</td>" +
                    "<td>" + filtrado[i].aliiva + "</td>" +
                    "<td><input type='radio' id='"+filtrado[i].idproducto+"' name='seleccion'/></td>"+
                    "</tr>";
                  
                $(newRow).appendTo("#resultado tbody");                 
       }
 
	
  
}};
function listar(){

    tipofiltro="todos";
	 $.ajax({
	  
            type: "POST",
            url: "includes/php/filtroP.php",
            data: { "tf": tipofiltro}, 
            dataType: "json",
            error: function(){
                alert("error petición ajax");
            },
            success: function(data){
     content=data;
               for (var i = 0; i < data.length; i++) {
          
                var newRow =
                    "<tr>" +
                    "<td>" + data[i].idproducto + "</td>" +
                    "<td>" + data[i].nombre + "</td>" +
                    "<td>" + data[i].marca + "</td>" +
                    "<td>" + data[i].categoria + "</td>" +
                    "<td>" + data[i].subcategoria + "</td>" +
                    "<td>" + data[i].precio + "</td>" +
                    "<td>" + data[i].aliiva + "</td>" +
                    "<td><input type='radio' id='"+data[i].idproducto+"' name='seleccion'/></td>"+
                    "</tr>";
                $(newRow).appendTo("#resultado tbody");                 
       
    
               
            }
        
  

        }  
}).fail( function( jqXHR, textStatus, errorThrown ) {

  if (jqXHR.status === 0) {

    alert('Not connect: Verify Network.');

  } else if (jqXHR.status == 404) {

    alert('Requested page not found [404]');

  } else if (jqXHR.status == 500) {

    alert('Internal Server Error [500].');

  } else if (textStatus === 'parsererror') {

    alert('Requested JSON parse failed.');

  } else if (textStatus === 'timeout') {

    alert('Time out error.');

  } else if (textStatus === 'abort') {

    alert('Ajax request aborted.');

  } else {

    alert('Uncaught Error: ' + jqXHR.responseText);

  }

});
};
  

});

Should the file be badly structured? On the other hand the functions go out of the ready?

    
asked by Caruso 14.09.2018 в 16:29
source

0 answers