Laravel Dynamic Form提交无响应

时间:2017-06-26 02:46:20

标签: ajax forms laravel dynamic submit

我有一个控制器(Laravel),它将动态创建一个表单,如下所示

<div class="row" style="margin-bottom:30px;margin-top:20px;">
  <div class="col-2">   
  <form class="addform" id="newcheckform" role="form">
        '.csrf_field().'  
    <label class="" for="cust_code">Cust Code</label>
    <input type="text" class="form-control" id="cust_code" value="'.$row->cust_no.'">
  </div>
  <div class="col-2">
    <label class="" for="cust_short">Cust Shortname</label>
    <input type="text" class="form-control" id="cust_short">
  </div>
  <div class="col-4">
    <label class="" for="cust_name">Cust Name</label> 
    <input type="text" class="form-control" id="cust_name" value="'.$row->cust.'">
  </div>
  <div class="col-2">
        <label class="" for="region">Region</label>
    <input type="text" class="form-control" id="region">
  </div>  
  <div class="col-2">
        <label class="" for="region">Add Cust Data</label>
    <button class="btn btn-sm btn-info"  id="createnewcust" type="submit">Create</button>
    </form>
  </div>  
</div>  

如果将由刀片文件中的以下脚本加载

$("#custcheck").load("{{ url('/sales/admin/custcheck') }}");

表格应显示为。 但是当我提交按钮时我。没啥事儿。代码如下。感谢任何人都可以提供帮助。此脚本位于同一个刀片文件中。

$(function() {
    $(document).on('submit', '#newcheckform', function(e){
        alert("Hi"); 
    });
});  

1 个答案:

答案 0 :(得分:1)

<form>有错误的结束标记更改此类内容:

<div class="row" style="margin-bottom:30px;margin-top:20px;">
  <form class="addform" id="newcheckform" role="form">
    {{csrf_field()}}  
  <div class="col-2">   
    <label class="" for="cust_code">Cust Code</label>
    <input type="text" class="form-control" id="cust_code" value="{{$row->cust_no}}">
  </div>
  <div class="col-2">
    <label class="" for="cust_short">Cust Shortname</label>
    <input type="text" class="form-control" id="cust_short">
  </div>
  <div class="col-4">
    <label class="" for="cust_name">Cust Name</label> 
    <input type="text" class="form-control" id="cust_name" value="{{$row->cust}}">
  </div>
  <div class="col-2">
    <label class="" for="region">Region</label>
    <input type="text" class="form-control" id="region">
  </div>  
  <div class="col-2">
    <label class="" for="region">Add Cust Data</label>
    <button class="btn btn-sm btn-info"  id="createnewcust" type="submit">Create</button>
  </div>  
  </form>
</div>  

这样可行。