<form id="print-shipping-label-form">
<input type="hidden" name="shipping_id" value="<?php echo $result_wpid_shipping['ID']; ?>">
<input type="hidden" name="api_key" value="ce312203c06e8bda7157c408fbac54c4">
<button type="submit" class="btn btn-danger">Drukuj list przewozowy</button>
</form>
<script>
document.addEventListener('DOMContentLoaded', function() {
var printShippingLabelForm = document.getElementById('print-shipping-label-form');
if (printShippingLabelForm) {
printShippingLabelForm.addEventListener('submit', function(event) {
event.preventDefault(); // Zatrzymaj domyślne zachowanie formularza
var formData = new FormData(printShippingLabelForm);
var url = 'https://torebki-fabiola.pl/?flexible_shipping_get_label=' + formData.get('shipping_id') + '&apikey=' + formData.get('api_key');
// Wykonaj żądanie AJAX
fetch(url, { method: 'POST' })
.then(function(response) {
return response.text();
})
.then(function(responseText) {
// Obsłuż odpowiedź z serwera, np. otwórz ją w nowym oknie.
window.open(responseText, '_blank');
})
.catch(function(error) {
console.log('Wystąpił błąd podczas wykonywania żądania AJAX: ' + error);
});
});
}
});
</script>
I try to fix problem with this code