Home  >  Q&A  >  body text

Why can't request get the value passed by ajax?

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



阿亦阿亦2392 days ago3199

reply all(8)I'll reply

  • 路过

    路过2018-04-26 08:29:21

    data:{

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

    }

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


    reply
    0
  • oswell

    oswell2018-04-25 14:04:05

    manual微信截图_20180425140235.png

    reply
    0
  • oswell

    oswell2018-04-25 13:54:17

    1. Is there a value in Form Data

      1. 315.png

    2. # # request whether to use


    3. reply
      0
  • 阿亦

    usedrequest form data also has a value, but it reports an undefined array index.

    阿亦 · 2018-04-25 13:59:09
    阿亦

    This is the value username in formdata: dwqd

    阿亦 · 2018-04-25 13:59:51
    oswell

    // 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 · 2018-04-25 14:02:04
    oswell

    Q45211930

    oswell · 2018-04-25 14:09:18
    阿亦

    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?

    阿亦 · 2018-04-25 14:07:30
  • Cancelreply