<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
3
Answers
You can use the fetch() method in JavaScript. This method is used to make AJAX requests and returns a promise that resolves to the response from the server. After the fetch() method, then() method is used to handle the response from the server. In this example, the response is converted to JSON and logged to the console. The catch() method is used to handle any errors that occur during the AJAX request.
“>
Drukuj list przewozowy
this is what it looks like after the corrections, but it doesn’t work either, please help