【问题标题】:How to print arrays in Laravel with innerHTML如何在 Laravel 中使用 innerHTML 打印数组
【发布时间】:2025-12-18 17:35:01
【问题描述】:

我收到一个带有 AjaxPetitions Array[0],Array1, Array[2] 的数组并正确接收信息。

$.ajax({
                url:'obtenersubastas',
                dataType:'json',
                type:'get',
                cache:true,
                success:  function (response) {
                    $(response).each(function(index,value)  {
                            console.log(response[index].nombre);
                            console.log(response[index].descripcion);
                            console.log(response[index].cant_actual);
                            console.log(response[index].images);
                            console.log(response[index].data_final);
                            console.log(response[index].id);
                    });

                },              
        });

我需要将此信息发送到一个名为 .nombre html 的类,有人可以帮助我吗?

更新

附加我有一个问题,我需要在页面中遵循一个样式,结果是这样的。

【问题讨论】:

    标签: javascript html arrays ajax laravel


    【解决方案1】:

    您可以使用 $('.nombre').html() 在选择器元素中添加您的值。

    试试这个代码

     $.ajax({
                url:'obtenersubastas',
                dataType:'json',
                type:'get',
                cache:true,
                success:  function (response) {
                    $(response).each(function(index,value)  {
                           $('.nombre').append('<p>Nombre :' +response[index].nombre +' descripcion: '+ response[index].descripcion + ' cant_actual: '+response[index].cant_actual +' images : '+ response[index].images +' data_final: '+ response[index].data_final +' id :'+ response[index].id+'</p>');
                    });
    
                },              
        });
    

    【讨论】:

    • 使用这种形式,我只能显示数组的一个元素,特别是最后一个。
    • @jcsa ,可以使用 .append() 代替 .html() 来获取所有数据。
    • 我做了这个改动,现在我解释了这个问题@Bhavin Solanki
    • 致@jcsa 我有这个问题的更新代码。我为每条新记录添加了 P 标签
    • @jcsa 乐于助人......我认为你需要使用一些引导类来获得正确的输出。如果您喜欢我的回答,请投票并接受,如果您愿意......