dongzhang7157
2016-12-07 14:51
浏览 106
已采纳

Laravel - 使用ajax将2个变量从视图传递到控制器

I have this function for my delete button

<a href="#" onclick='deleteFile("{{ ($event->id) }}", "{{ ($file->name) }}")' class="btn btn-danger btn-xs delete">L&ouml;schen</a>

and the route in routes/web.php

Route::post('/delete-file', 'MyController@deleteEventFile');

that hits this function

public function deleteEventFile($eventid, $filename){
   dd($eventid);
}

and this is my ajax function:

function deleteFile(eventid, filename){
    //alert(filename);
    //alert(eventid);
    $.ajax({
      url: '/delete-file/',
      type: "post",
      data:{ _token: "{{csrf_token()}}", eventid: eventid, filename: filename },
      dataType: 'json',
    });
}

And i always get this error:

Missing argument 1 for App\Http\Controllers\MyController::deleteEventFile()

my variables can't get through... How to pass the eventid and filename to controller

图片转代码服务由CSDN问答提供 功能建议

我的删除按钮有这个功能

 &lt;  a href =“#”onclick ='deleteFile(“{{($ event-&gt; id)}}”,“{{($ file-&gt; name)}}”)'class =“btn btn-danger btn  -xs删除“&gt; L&amp; ouml; schen&lt; / a&gt; 
   
 
 

以及routes / web.php中的路由 < pre> Route :: post('/ delete-file','MyController @ deleteEventFile');

点击此功能 \ n

  public function deleteEventFile($ eventid,$ filename){
 dd($ eventid); 
} 
   
 
 

and this 是我的ajax函数:

  function deleteFile(eventid,filename){
 // alert(filename); 
 // alert(eventid); 
 $ .ajax  ({
 url:'/ delete-file /',
 type:“post”,
 data:{_ token:“{{csrf_token()}}”,eventid:eventid,filename:filename},
  dataType:'json',
}); 
} 
   
 
 

我总是收到此错误:

 < 代码> App \ Http \ Controllers \ MyController ::缺少参数1 ::  deleteEventFile()
   
 
 

我的变量无法通过... 如何将eventid和文件名传递给控制器​​

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题