Why can't request get the value passed by ajax?
阿亦
阿亦 2018-04-25 13:43:26
0
8
3229

ajax part:

$.ajax({
type:"post",
url:"{:url('Contact/sendEmail')}",
data: "username=" $("#username").val(),
//dataType:'json',
success: function (data) {
alert(data);
}
})

thinkphp part:

//Send email
public function sendEmail(Request $request){
$data = $request->param(); //Return information
$name = $data['username'];

Supplement: There is no problem with the path, and request

is also used to report error:

Not yet Define array index: username



阿亦
阿亦

reply all(3)
路过

data:{

'username' : $("#username").val()

}

In ajax, data is replaced with an object ? ? ?


legend

manual微信截图_20180425140235.png

legend
  1. Is there a value in Form Data

    1. 315.png

  2. # # request whether to use


  • reply usedrequest form data also has a value, but it reports an undefined array index.
    阿亦 author 2018-04-25 13:59:09
  • reply This is the value username in formdata: dwqd
    阿亦 author 2018-04-25 13:59:51
  • reply // Get the name variable of the current request Request::instance()->param('name'); // Get all variables of the current request (filtered) Request::instance()->param(); // Get all variables of the current request (original data) Request::instance()->param(false); // Get all variables of the current request (including uploaded files) Request::instance()->param(true);
    oswell author 2018-04-25 14:02:04
  • reply Q45211930
    oswell author 2018-04-25 14:09:18
  • reply Thank you, but I feel like this is bothering me. In the past $data = $request->param(); I could get the information like this. Can you leave me your contact information?
    阿亦 author 2018-04-25 14:07:30
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template