作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我几天来一直遇到无法解决的问题。
我的 View 中应该有一个 javascript/ajax/jQuery 函数,它创建一个数组并使用路由“/modulos/contas_ti/gerar_protocolo”将用户发送到新页面
这是我的 JavaScript:
function check() {
// I don't know how many numbers I will have in my array.
// It will be dinamic. Can be [1, 2] or [1, 4, 5, 6] or anything else.
var array = [1, 2];
// I would like to pass 'array' in the URL below as parameter
window.location.href = "{{URL::to('/modulos/contas_ti/gerar_protocolo')}}"
}
我的路线:
// Maybe pass the array at the end of 'gerar_protocolo'?
// Like 'gerar_protocolo[]=' ?
Route::get('/modulos/contas_ti/gerar_protocolo', 'ContasTI\ContasTIController@gerarProtocolo');
我的 Controller :
// How to pass the array as parameter inside ()? I also need to
// pass the array to the new view using 'with', right?
// Like with->('datas', $data);
public function gerarProtocolo() {
return view('modulos.contas-ti.gerar_protocolo');
}
最佳答案
您可以将其作为请求参数发送
function check() {
var array = [1, 2];
window.location.href = "{{URL::to('/modulos/contas_ti/gerar_protocolo')}}" + "?array[]=1&array[]=2";
}
Controller :
public function gerarProtocolo(Request $request) {
$data = request('array');
return view('modulos.contas-ti.gerar_protocolo', compact('data'));
}
关于javascript - 如何将数组从 View 传递到 Controller ?使用 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548672/
我是一名优秀的程序员,十分优秀!