I have a compatibility issue with Safari and all iOS devices. I created this jQuery code (see the link below ) for a project but I don’t understand why it doesn’t work with Safari.
With the Chrome, Firefox, Android it works well.
(function ($) {
$.ajaxSetup({ cache: false });
const ajax_dir = '/wp-content/plugins/oxygen-functions/assets/ajax/';
// SELECT LOCATION-SERVICE FORM
$('.serv-select select').html(select_vars.services_select);
$('.loc-select select').html(select_vars.locations_select);
$('.service-location-form')
.closest('form')
.submit(async function (e) {
e.preventDefault();
$(this).find('.frm_message').addClass('d-none');
var form = $(this).serializeArray(),
service = form.find((x) => x['name'] == `item_meta[33]`).value,
loc = form.find((x) => x['name'] == `item_meta[34]`).value,
cat = loc + ',' + service,
posts = await $.ajax({
type: 'post',
async: true,
url: ajax_dir + 'posts-by-cat.php',
dataType: 'json',
data: {
post_type: 'services',
cat: cat,
},
}),
url = await $.ajax({
type: 'post',
async: true,
url: ajax_dir + 'post-link-id.php',
dataType: 'json',
data: {
id: posts[0],
},
});
//console.log(url);
location.href = url;
});
})(jQuery);
This is the error that I getting from the DevConsole:
Unhandled Promise Rejection [object Object]
(anonymous function) - scripts.js:21
asyncFunctionResume
(anonymous function)
promiseReactionJobWithoutPromise
How I can fix it? some idea?
Thanks!
3
Answers
This is the whole snippet:
Currently, your code doesn’t have any error catching blocks.
Try to insert the function content into the
try/catch
blockTry using a
return false
statement after ajax call