How to send an html array by ajax?

0

I have the following html array:

@foreach($lab->categoria as $cat)
    <label style="color:#000;margin-top:0px; margin-botton:0px"  data-nombre="{{$cat->nombre}}"><i class="fa fa-mars"></i> {{$cat->nombre}} <input value="{{$cat->id}}" name="categorialab_id[]" type="checkbox" ></label>
@endforeach 

That I want to send via ajax to process them with php (laravel), in case it is not ajax in the controller I would do:

$array=$request->categorialab_id;
for($i=0;$i<count($array);$i++){
   $new=new Estudioslab();
   $new->estudioslab_id=$dato->id;
   $new->categorialab_id=$array[$i];
   $new->save();
}

The fact is that wanting to send via ajax this does not leave me and I get the error of:

  

Uncaught TypeError: Illegal invocation
      at i (jquery.min.js: 2)
      at jt (jquery.min.js: 2)
      at Function.w.param (jquery.min.js: 2)
      at Function.ajax (jquery.min.js: 2)
      at HTMLFormElement. (2: 3232)
      at HTMLFormElement.dispatch (jquery.min.js: 2)
      at HTMLFormElement.y.handle (jquery.min.js: 2)

my ajax is this:

$("#subirlaboratorio").submit(function(e){
    e.preventDefault();
    $("#btn-save-laboratorio").attr("disabled",true);
    var formData = new FormData($("#subirlaboratorio")[0]);

    $bool=confirm("Seguro de Solicitar los examenes de laboratorio?");
    if($bool){
        $.ajax({
            url:url_global+"/crearlabestudio",
            type:'get',
            data:formData,
            success:function(data){
                if(data.resp==200){

                    toastr.success(data.msn);
                    window.open(url_global+'/printlaboratorio/'+data.dato.id+'/'+paciente_id,"Imprimir","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
                }else{
                    toastr.error(data.msn);
                }
            },
            error:function(data){  
                toastr.error(data.msn);
            }
        }); 
    }
});
    
asked by Shassain 22.12.2018 в 07:29
source

1 answer

0

The error is not really the html array, what happens is that jQuery tries to convert the FormData object to a string, which is usually solved by setting these parameters to false in the jQuery ajax request:

processData: false,
contentType: false
    
answered by 22.12.2018 в 16:09