我的把手有问题,
我已经导入了把手库和jquery,一切似乎都运行正常。 问题是,当我有一个响应ajax并将其传递给车把,然后我尝试打开它没有显示任何内容。
的javascript
<script>
var userTable = $('#user-table'); // Ambil tempat template akan dimasukan
var itemUserTableRaw = $('#user-item-table').html(); // Ambil template
var itemUserTableTemplate = Handlebars.compile(itemUserTableRaw); // Compile template menjadi handlebars template
$(function () {
var token = $('meta[name="csrf-token"]').attr('content');
var header = "X-CSRF-TOKEN";
$(document).ajaxSend(function (e, xhr, options) {
xhr.setRequestHeader(header, token);
});
});
$.ajax({
method: 'get',
crossDomain: true,
dataType: 'json',
url: "http://localhost:9090/users",
}).then(function (response) {
userTable.html(itemUserTableTemplate(response));
});
</script>
车把模板
<script id="user-table" type="text/x-handlebars-template">
{{#each data}}
<tr>
<td>{{username}}</td>
<td>{{password}}</td>
</tr>
{{/each}}
</script>
view.blade.php
<table id="tabel" class="table table-bordered table-hover">
<thead>
<th class="col-head" >
Username
</th>
<th class="col-head" >
Password
</th>
</thead>
<tbody id=user-item-table>
</tbody>
</table>
@include('/handlebars/user')
<script src="{{ asset('node_modules/jquery/dist/jquery.min.js')}}"></script>
<script src="{{ asset('node_modules/handlebars/dist/handlebars.min.js')}}"></script>
<script src="{{ asset('Assets/user.js')}}"></script>
感谢您的帮助