douyoufan7881 2018-09-30 18:46
浏览 70

在Laravel 5.3中使用AJAX更新表无法正常工作

I trying to use an AJAX PUT request to update a row in my database and I am trying to send the request to my controller. This is my AJAX call:


    var truckNo = $('#XA').val();
    var truckOwner = $('#truck-owner').val();
    var vehicle_number = $('#vehicle-number').val();
    var capacity = $('#capacity').val();
    var end_of_insurance = $('#end-of-insurance').val();
    var end_of_kteo = $('#end-of-KTEO').val();
    var truckCode = $('#truck-code').val();
    var leased = $('#leased').val();
    var truckModel = $('#truck-model').val(); 

        url: 'editTruck',
        type: 'put',           
        data: {
            truckNo: truckNo,
            truckOwner: truckOwner,
            vehicle_number: vehicle_number,
            capacity: capacity,
            end_of_insurance: end_of_insurance,
            end_of_kteo: end_of_kteo,
            truckCode: truckCode,
            leased: leased,
            truckModel: truckModel
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        contentType: 'application/json',
        dataType: 'JSON',
        success: function(){
        error: function(){
           console.log('something went wrong');

So far so good. If I console.log() my data is seems I can get them from the form. I am using Laravel Collective for the form:

 {!!Form::open(array('action' => ['Trucks@editTruck'], 'method' => 'put')) !!}  

and my route is the following:

Route::put('/editTruck', 'Trucks@editTruck',function(){ });

Now I am using Request $request in the parameters of the controller but somehow it looks like I cannot get the incoming values. For example the following var_dump will say NULL.

public function editTruck(Request $request)
      $data = $request->input('truckNo');

Same happens if I use

$data = $request->truckNo;

instead. So I am wondering how can I get the values that are been sent to my controller with my AJAX call? Why am I getting NULL values?

What I was planning to do is:

 public function editTruck(Request $request)
       $singleTruck = Truck::find($request->truckNo);          
       $singleTruck->truckNo = $request->input('truckNo'); 
       $singleTruck->truckOwner = $request->input('truckOwner');
  • 写回答

2条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 VBA中使用FindWindowEx函数如何向网页表单中的多个文本框中的某一个文本框发送消息
      • ¥15 关于#glmb#的问题,如何解决?
      • ¥15 TI的TMS320F28335,RS485串口进行SCI-B通信出错
      • ¥15 XML文件报错不允许出现此特性,百度也搜不到解决方法
      • ¥15 FTPC共同交流学习
      • ¥15 关于#python##pyqt#的问题,如何解决?
      • ¥15 html+css网页设计 html+css网页设计
      • ¥15 用html加css制作一个网页
      • ¥200 MFC中如何对ListCtrl的某一列的文本能换行显示
      • ¥15 clion添加库文件