0

I have text and image input in a form. I want to send the data through ajax request. I use dataForm as the format to send to Laravel controller. I get array(0) {} when i try to retrieve the input form.

This is my ajax request code:

$("form").on('submit', function(){

var data = new FormData(this);
var url = "{{ route('ajaxSubmitFormWizardsEmployee') }}";
var csrf_token = $(this).find('input[name="_token"]').val();

$.ajaxSetup({
     headers: {
    'X-CSRF-TOKEN': csrf_token,
     }
});
$.ajax({
 type: "POST",
 url: url,
 async: false,
 cache: false,
 contentType: false,
 processData: false,
    data: {
        data : data,
    },
    success:function(data){
    console.log(data);
    },
     error: function() {
    console.log('error);
     },
    
}); 

Laravel controller:

public function ajaxSubmitFormWizardsEmployee(Request $request) {
    $input = $request->all();        
    print_r($input);
}

I managed to console log the formData before send ajax by adding this code:

for (let obj of data) {
   console.log(obj[0],obj[1]);
}

Below is the picture console log the formData before send ajax: console log the formData before send ajax

Below is the picture console log when try to retrieve or view data from Laravel controller: retrieve or view data from Laravel controller

1 Answer 1

0

I see that you are trying to submit a file, does your form have this attribute:

enctype="multipart/form-data"
Sign up to request clarification or add additional context in comments.

1 Comment

yes it does. i have that attribute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.