D
D
Dmitry Chilikin2020-02-07 17:59:26
Laravel
Dmitry Chilikin, 2020-02-07 17:59:26

Why doesn't the $request array in Laravel contain data from an ajax submitted form?

Good afternoon!
I need to upload a file and a couple of text fields from the page to the server. I made a form in HTML, I send it to the server via AJAX:
HTML:

var formData = new FormData();
    var file = document.getElementById("fileToLoad");
    formData.append("fileToLoad", file.files[0]);
    formData.append('now', $('#dateToLoad').val());
    formData.append('test', 'test');
    $.ajax({
      url: '/counters/indication/loadFile',
      data: formData,
      type: 'PUT',
      contentType: false,
      processData: false,
      success: function(msg) {
        console.log(msg);
      }
    });


Next, I implement the loadFile function in the controller:
public function loadFile(Request $request)
    {
    var_dump($request->test);
    die();
  }

In the javascript console of the browser, the value of the test field from formdata should "fly" to me, but NULL comes instead.

What's the catch?

ps: PHP 7.1.3, Laravel 5.8.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-02-07
@peacock

https://laravel.com/docs/6.x/blade#method-field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question