Nefungujíci ajax, ale jen v jedné komponentě
- bautren
- Člen | 7
Zdravím, když chci odeslat ajax dotaz na jiných komponentách, tak mi to bez problému funguje, ale když to chci odeslat z tohoto
CheckoutDetailControl.latte
tak mi to vyhodí chybu, viz. níže
snippet checkoutDetail}
<table class="table">
{var $couponSale = ($wine * $coupon)}
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Zboží</td>
<td>{$wine} Kč</td>
</tr>
<tr>
<td>Sleva</td>
<td>{$couponSale} Kč</td>
</tr>
<tr>
<td>Doprava</td>
<td>{$transport} Kč</td>
</tr>
<tr>
<td>Platba</td>
<td>0 Kč</td>
</tr>
<tr>
<td>Celková cena</td>
<td>{($wine - $couponSale) + $transport} Kč</td>
</tr>
</tbody>
</table>
{/snippet}
{block jsCallback}
<script>
document.addEventListener('DOMContentLoaded', function () {
$(function(){
$.nette.ext("initOnAjax", {
success: function (payload) {
if (!payload.redirect) {
jsInit();
}
}
});
jsInit();
});
function callAjax(url) {
console.log(url); // TODO ms LOG
$.nette.ajax({
type: 'POST',
url: url.toString(),
success: function (data) {
if (!data.redirect) {
}
$("#snippet-checkoutDetailControl-checkoutDetail").html(data.snippets['checkoutDetailControl-checkoutDetail']);
}
})
}
function jsInit() {
let transportMethodInput = $('input[name="transportMethod"]');
transportMethodInput.on('click', function(e) {
let method = $(e.currentTarget)
let url = new URL(location.href);
url.searchParams.append('do', 'checkoutDetailControl-changeTransport')
url.searchParams.append('method', method.val());
callAjax(url)
})
}
})
</script>
{/block}
CHYBA
index.js?ea28:6 Uncaught TypeError: Cannot read properties of undefined (reading 'el')
at Object.before (index.js?ea28:6)
at Function.eval (nette.ajax.js?c417:42)
at Function.each (jquery.js?1157:391)
at Object.fire (nette.ajax.js?c417:40)
at Object.settings.beforeSend (nette.ajax.js?c417:215)
at Function.ajax (jquery.js?1157:9648)
at nette.ajax (nette.ajax.js?c417:225)
at callAjax ((index):305)
at HTMLInputElement.<anonymous> ((index):325)
at HTMLInputElement.dispatch (jquery.js?1157:5430)
Děkuji
Editoval bautren (16. 9. 2021 23:58)