jquery - How to assign dynamically fetched variable to HREF, Jquery, laravel
问题描述
I am new to development, apologies if question is basic
I am trying to add href page to the btn, but when the blade template parses url it's formatted and return error.
$('#municipal_option').on('change',function(e){
// console.log(e);
var municipal_id = e.target.value;
var BASEURL = "{!! url('admin/bank/') !!}";
console.log(municipal_id);
$.get( BASEURL + '/bankview?municipal_id=' + municipal_id, function(data){
console.log(data);
$("#bank_list tr").remove();
$.each(data,function(index, bankObj){
$('#bank_list').append('<tr class=""><td> ' + bankObj.bank_name + '</td> <td> ' + bankObj.bank_ac_no + ' </td> <td> '+ bankObj.bank_ifsc_code +' </td> <td> <button class="btn btn-primary"> **<a href="{!! asset('bank/{{$bank->id}}/edit')!!}"> Edit </a>** </td> <td> </td> </tr>');
});
});
});
The route:
| GET|HEAD | bank/{bank}/edit | bank.edit | App\Http\Controllers\bankController@edit
How to point to the above route.
The url that's generated, http://localhost/public/bank/%3C?php%20echo%20e($bank-%3Eid);%20?%3E/edit
Adding to the above question, Instead of looping the result(table) in the code, can I use it independently in the blade template with hep of @foreach.
Thank you.
解决方案
使用Javascript将自定义js值替换到路由中
var url = "{{ route('bank.edit', ':municipal_id') }}";
url = url.replace(":municipal_id", municipal_id);
所以...
$('#municipal_option').on('change',function(e){
// console.log(e);
var municipal_id = e.target.value;
var BASEURL = "{{ route('bank.edit', ':municipal_id') }}";
BASEURL.replace(':municipal_id', municipal_id);
console.log(municipal_id);
$.get( BASEURL , function(data){
console.log(data);
$("#bank_list tr").remove();
$.each(data,function(index, bankObj){
$('#bank_list').append('<tr class=""><td> ' + bankObj.bank_name + '</td> <td> ' + bankObj.bank_ac_no + ' </td> <td> '+ bankObj.bank_ifsc_code +' </td> <td> <button class="btn btn-primary"> **<a href="{!! asset('bank/{{$bank->id}}/edit')!!}"> Edit </a>** </td> <td> </td> </tr>');
});
});
});
推荐阅读
- javascript - 使用多维数组的登录页面?
- java - 如何通过标签名称检索多个标签中的元素以进行硒自动化测试
- localization - 使用清单的 MS Teams 应用本地化不起作用
- r - 将顶点属性数据从 igraph 移动到矩阵
- c# - 是否可以为代码重复创建方法?
- azure - 如何通过验证源和目标中文件的大小来归档 Azure 数据湖中的数据
- linux - 如果我们允许 root 用户特权在一个 pod 中进行进程,co pod 是否有任何风险?
- sql - 如何调试此查询
- javascript - 使用 NODE.js 在 MySQL 数据库中查找电子邮件
- javascript - 如何在 Firestore 文档中创建 Auto-ID?