javascript - 如何向控制器发送多个 id
问题描述
我想将我的 id 发送到控制器,但我的 id 被逗号分隔212,233,121
,例如来自 JavaScript。如何根据我的基于 JavaScript 的数字逗号拆分的值发送我的 id?
url 应该是这样http://localhost/fics/public/reporting/reporting/getcust/212/233/121
的,它是后面的数字,基于我用逗号分隔的值。
这是我的代码:
for (var h = 0; h < storeItem.length; h++)
{
if (l == storeItem[h]) {
popVal = popVal + tempItem[i][l];
//popval value from my other window .Example " 002,212,212"
}
}
我的查看路线按钮onclick:
onclick="openNewWindow('{{ route('reporting.getcust') }}')"
我的 web.php:
Route::group(['prefix' => 'reporting'], function () {
Route::get('reporting/getcust/{id}','GenReportController@getcust')->name('reporting.getcust');
});
控制器:
public function getcust(Request $request){
$id = $_GET['id'];
}
解决方案
如果 JavaScript 生成类似http://localhost/fics/public/reporting/reporting/getcust/002,212,212的 URL 。然后您可以使用该explode
方法获取控制器中的所有ID
public function getcust(Request $request)
{
$ids = explode(",", $request->id);
foreach ($ids as $id)
{
echo $id;
}
}
推荐阅读
- sql - 在 SQL 中连接时删除的数字的零前导数字
- azureservicebus - 如何使用 MassTransit 从 Azure 死信队列中读取消息
- android-studio - Kotlin 编译错误:使用不兼容的 Kotlin 版本编译模块
- docker - 如何在同一台计算机上运行多个 localhost?
- python - 我需要将列表列表转换为要在 python 中的电子邮件中发送的表格
- javascript - React Semantic UI Modal closeicon 不起作用
- c - 转换/访问相同的内存是 C 中的不同变量
- c# - FluentValidation IRuleBuilderOptions 扩展方法 - 如果值存在,则仅运行正则表达式验证器
- tensorflow - 为什么纯张量流自动编码器不能收敛,当 Keras 适合时
- python - 获取Bot的频道?不和谐.py