如何使用laravel / ajax

时间:2017-08-07 07:52:27

标签: php jquery ajax laravel

我有以下jQuery代码,我可以通过这个循环获取我的HTML元素。我想获取我的数据并通过AJAX将其存储到数据库中。我该怎么办?

$('#btnSubmit').on('click', function(){
  for(var increment = 0; increment <= pos_inc; increment++) {
    var text1 = $('#orders' + increment).val();
    var text2 = $('#item_quan' + increment).val();
    var text3 = $('#price_tot' + increment).val();
  }
});

HTML

   <table class="table dynamic_field">                        
   <label>OR Number:&nbsp;&nbsp;<span id="sp_or"><?php echo $or_no; ?></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   <br>
   <br>
   Sold To:&nbsp;&nbsp;<span id="sp_name"><?php echo $name; ?></span></label>
   <thead>
   <th>Items</th>
   <th>Qty</th>
   <th>Total</th>
   </thead>
   <tbody>
   {{ csrf_field() }}
  <!-- empty -->
  </tbody>
  </table>
  <!-- hidden input-->
  <input type="hidden" id="inc" value="<?php echo $inc; ?>">
  <input type="hidden" id="or" name="or">
  <input type="hidden" id="cus_name" name="cus_name">
  <input type="hidden" id="total" name="total">
  <!-- end of hidden input-->

  <label>TOTAL:&nbsp;&nbsp;&nbsp;<span id="sp_tot"><?php echo $total; ?></span></label>
  <br>
  <label>CUSTOMER CHANGE:&nbsp;&nbsp;&nbsp;<?php echo $change; ?></label>
  <br>
  <br>
  <br>
  <a href="{{ url('use-pos') }}">
  <button type="button" class="btn btn-default">Go Back</button>
  </a>&nbsp;
  <input type="button" class="btn btn-success" value="Complete Purchase" id="btnSubmit">
</form>

在我的控制器中:

public function DoAddSales(Request $request){
    return $request->all();
}

1 个答案:

答案 0 :(得分:0)

这是你的解决方案,

['\n',' ','a']