¿Me falta agregar algún script o qué? Recibo un error del título. Como puedo solucionar esto, si me pueden ayudar se los agradeceria. Intenté agregar diferentes scripts, pero obtengo el mismo error.
<a onclick="buyNft({{$nft->id}})">{{trans('nft.buy')}}</a> @push('scripts') <script> function buyNft(nftid) { swal({ title: "Are You Sure?", text: "Do you want to buy this nft?", type: 'warning', showCancelButton: true, showConfirmButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', }).then((result) => { if (result) { axios.post("/buythisnft/" + nftid).then(response => { window.location.reload(); }); } }); } </script> @endpushSu función buyNft debe declararse ANTES de repetir cualquier elemento con "onclick=buyNft()":
@push('scripts') <script> function buyNft(nftid) { // ... } </script> @endpush <a onclick="buyNft({{$nft->id}})">{{trans('nft.buy')}}</a>ACTUALIZACIÓN: este es un ejemplo que usa un script en la parte inferior de la página que crea un detector de eventos para eventos de clic:
document.addEventListener("click",e => { if(e.target.closest(".buyNft")){ e.preventDefault(); alert("You want to buy an NFT.") //... Replace with your own functions ... } }) <a class="buyNft" href="#">Buy that NFT</a> <br /><br /> <a href="#">Some other link on this page</a>