I keep getting the following error Error: "Window navigated away"
and I dont know how to stop this error from occuring when it does happen it also keeps me from leaving the current web page that I'm on. I'm fairly new to Jquery and Javascript so I kind of need lots of help on how to stop this from occuring.
Here is my code
if($('#button').length){
paypal.Buttons({
env: '<?= PAYPAL_ENVIRONMENT ?>',
style:{
height: 100,
},
createOrder: function() {
let formData = new FormData();
formData.append('return_url', '<?= $baseUrl.$URL["redirectUrls"]["returnUrl"]?>' + '?commit=false');
formData.append('cancel_url', '<?= $baseUrl.$URL["redirectUrls"]["cancelUrl"]?>');
return fetch('<?= $rootPath.$URL['services']['orderCreate']?>',
{
method: 'POST',
body: formData
}
).then(function(response) {
return response.json();
}).then(function(resJson) {
var txt = resJson.data.id;
$.post('createid.php', {
order_id: txt
});
return resJson.data.id;
});
},
onApprove: function(data, actions) {
return fetch(
'<?= $rootPath.$URL['services']['orderGet'] ?>',
{
method: 'GET'
}
).then(function(res) {
return res.json();
}).then(function(res) {
$('.nonce').val(res.data.id);
});
},
onCancel: function(data) {
$('#c').html('<a id="anchor" name="anchor"><p>Cancelled order.</p></a>');
location.href = '#cancelled';
},
onError: function(err) {
$('#e').html('<a id="anchor" name="anchor"><p>Error.</p></a>');
location.href = '#error';
}
}).render('#button');
}