Append from ajax

0

I have this AJAX

$.ajax({
                        type: 'POST',
                        url: "libreria.php?cmd=" + comando,
                        dataType: 'json',
                        async: false,
                        data: params,
                        headers: {
                        "accept": "application/json",
                        },
                    }).done(function (result3){
                    respuesta4 = result3;
                        var totalCC = listccostos;
                        var listccostos2 = [];
                        for(var i = 0; i < respuesta4.length; i++)
                        {
                            var TCcostos = respuesta4[i];
                            for(var j = 0; j < totalCC.length; j++)
                            {
                                if(totalCC[j].value == respuesta4[i].CentroCosto)
                                {
                                    listccostos2.push(totalCC[j]);
                                    console.log(listccostos2);
                                  //aqui va el append
                                }
                            }
                        }

                    }).fail(function(xhr){
                        console.log('error', xhr);
                    });

What it does is bring me information from the database

Now what I need and I do not know how to do is to this td

cols += '<td> <input class = "c_costos c_validar" id="CentroCosto' + counter2 + '"  size="20" autocomplete="off" > </td>';

I need to add this

$("#CentroCosto"   + counter2).autocomplete({source: listccostos2,    minLength: 0}).focus(function() {    $(this).autocomplete('search', $(this).val())});

from the ajax with Append.

Some idea to do it.

    
asked by Eduard 07.02.2018 в 14:29
source

1 answer

2

First make the append necessary to add the TD when you finish the necessary l'+ ines do the:

$("#CentroCosto"   + counter2).autocomplete({source: listccostos2,    minLength: 0}).focus(function() {    $(this).autocomplete('search', $(this).val())});

To give you a headache with the ids "# Centrocost1, # Centrocost2, ...." uses classes is more optimal.

Greetings.

    
answered by 07.02.2018 / 15:42
source