con questo invece :

codice:
     // Initialize select2
     $("#id_id_comuni").select2({
        theme: "bootstrap-5",
        ajax: { 
          url: "<?= base_url('AjaxRequest/getComuniSelect')?>",
          type: "post",
          dataType: 'json',
          delay: 250,
          data: function (params) {
             // CSRF Hash
             var csrfName = $('.txt_csrfname').attr('name'); // CSRF Token name
             var csrfHash = $('.txt_csrfname').val(); // CSRF hash


             return {
                searchTerm: params.term, // search term
                [csrfName]: csrfHash // CSRF Token
             };
          },
          processResults: function (response) {


             console.log(JSON.stringify(response.data));
 
             // Update CSRF Token
             $('.txt_csrfname').val(response.token); 


            $.each(response.data, function (i) {
                $.each(response.data[i], function () {
                    //console.log(response.data[i]['id']+' '+response.data[i]['cap'] );
                    $("#id_id_comuni").html("<option value='"+response.data[i]['id']+"'>"+response.data[i]['cap']+" " +response.data[i]['localita']+"</option>")
                });            
            });


            return {
                results: response.data
            };




          },
          cache: true
        }
     });
scrivo nel input di select 2 appare correttamente il risultato ma non vedo le option