Home>

In Laravel + JQuery, when I clicked the button, I sent a POST request to the controller with Ajax, and when I returned the value sent to the controller to the JS side again, the value became undefined.
I'm investigating the cause, but I can't figure out the cause ...
When I checked the network part on the chrome console, it seems that communication is working well with status code 200.

I would appreciate it if you could tell me the cause. Thanks for your cooperation.

$("# bt2"). click (function () {
  $.ajaxSetup ({
  headers: {
    "X-CSRF-TOKEN": $('meta [name = "csrf-token"]'). Attr ("content"),
  },
});
  $.ajax ({{
    // POST communication
    type: "post",
    // Specify the URL to send the data here.
    url: "/ postgmail",
    dataType: "json"
    data: {
      uid: 100,
      subject: "test subject",
      from: "test from",
      body: "test body",
    },
  })
    // When communication is successful
    .then ((res) =>{
     console.log ("[Communication succeeded]->Result:" + res.message);
    })
    // When communication fails
    .fail ((error) =>{
      console.log (error.statusText);
    });
});

The communication is successful, but the returned value is undefind as shown below.

// Controller side
  public function postGmail (Request $request)
  {
    $result = $request->all ();
    return $result;
  }
// web.php
Route :: post ('/ postgmail','HomeController @ postGmail');