aureliee123
7 months ago
1075
16
Laravel

loop over an array sent with ajax to controller

Posted 7 months ago by aureliee123

Hello , i'm using an ajax post request to send an array ( selectedids) to the controller

$.ajax({

        type:'POST',

        url:'{{action('[email protected]')}}',

        data: { "type":strUser , "_token": "{{ csrf_token() }}","ids":JSON.stringify(selectedIds)},

        dataType: 'json',
                    
        success:function(data){
        
            alert(data);

        },
        error: function(xhr, textStatus, thrownError) {
                alert(' Error');
        }
        
    });

but i cannot loop over it in the controller i tried json_decode but it didn't work

the only thing that worked is :

echo $request->get("ids");

it shows this : 14,21,12 how can i iterate over it to get all the ids

thank you

Please sign in or create an account to participate in this conversation.