$( document ).ready(function() { function stopRedirect(){ let text = $("#textRicercaArtigiani").val(); if (typeof text != "undefined" && text != null && text.trim() != "") { return true } return false; } select2CategorieMadri.on("change", function (e) { if( typeof event != "undefined" ) { let id_categoria = $(this).val(); if (!stopRedirect()) { $.ajax({ type: 'POST', url: 'https://www.ilcercartigianodiqualita.it/assets/ajax/get-url-sottocategoria.php', data: {id_categoria: id_categoria}, dataType: 'json', success: function (response) { if (response.status == 'success') { if (typeof response.url_categoria != "undefined" && response.url_categoria != null && response.url_categoria.trim() != "") { window.location.replace(response.url_categoria); } } }, error: function (xhr, ajaxOptions, thrownError) { } }); } } }); select2Province.on("change", function (e) { if( typeof event != "undefined" ) { let id_location = $(this).val(); if (!stopRedirect()) { $.ajax({ type: 'POST', url: 'https://www.ilcercartigianodiqualita.it/assets/ajax/get-url-location.php', data: {id_location: id_location}, dataType: 'json', success: function (response) { if (response.status == 'success') { if (typeof response.url_location != "undefined" && response.url_location != null && response.url_location.trim() != "") { window.location.replace(response.url_location); } } }, error: function (xhr, ajaxOptions, thrownError) { } }); } } }); });