dsaj20411 2017-06-07 14:10
浏览 13
已采纳

Laravel表单不发送动态生成内容的请求

I have a form like this:

<form class="form-horizontal" role="form" method="POST" name="myform" id="myform" action="{{ url('/mypage/') }}">
        {{ csrf_field() }}
<div id="somecontent">
</div>
<div id="abutton">
</div>
</form>

Then some Jquery like this:

 $('#somecontent').html('<select class="form-control" id="myselect"  form="my"><option value="1">Hello</option><option value="2">World</option></select>');

And then I add a button like this:

button = $('<button type="submit" form="myform" class="btn btn-theme">Send</button>');

$('#abutton').html(button);

And I also change the action dynamically:

 $("#myform").attr("action","/mypage/" + item_id);

Then I got this in the web file:

Route::post('/mypage/{item_id}','mycontroller@do_something');

And then do this in the controller:

public function do_something($item_id,Request $request){
dd($request);
}

But the $request is empty, it does not contain the value selected in the dynamically generated select.

Any ideas why?

  • 写回答

1条回答 默认 最新

  • donglu3243 2017-06-07 14:30
    关注

    you haven't added name attribute of select, add name attribute and see it will populate into $request.

    Try below code.

     $('#somecontent').html('<select name="select_name" class="form-control" id="myselect"  form="my"><option value="1">Hello</option><option value="2">World</option></select>');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)