Jump to content

Function JS not working with the italian language


Recommended Posts

Hi Guys,

I have a little JS function, that delete the stored carts. That work nice with all the language, but with the italian he do just a refresh of page. What could be the problem ? It s like he can't find the function...

Here the funcition:

 

function deleteCart(id, name) {
            if (confirm('{l s='Delete cart' mod='addtocartfromurl'}' + ' ' + name + '. {l s='Are you sure?' mod='addtocartfromurl'}') === true) {
                //$('button#submitDeleteSavedCart').attr('disabled','disabled').addClass('disabled').removeClass('active');
                $('button#submitDeleteSavedCart').attr('disabled','disabled');
                $.ajax({
                    type: 'POST',
                    url: '{$cart_controller|escape:"quotes":"UTF-8"}',
                    async: true,
                    cache: false,
                    dataType: "json",
                    data: 'method=delete&id=' + id + '&token=' + '{$token|escape:'htmlall':'UTF-8'}',
                    success: function (jsonData) {
                        //$('button#submitDeleteSavedCart').removeAttr('disabled').removeClass('disabled');
                        $('button#submitDeleteSavedCart').removeAttr('disabled');
                        if (jsonData.response.result === 'OK') {
                            $('div.addtocartfromurl_' + id).hide('slow', function(){
                                $('div.addtocartfromurl_' + id).remove();
                            });
                            $('div.addtocartfromurl-saved-cart-messages').addClass('addtocartfromurl-saved-cart-messages-alert alert alert-success').text('{l s='Cart deleted successfully.' mod='addtocartfromurl'}');
                        } else if (jsonData.response.result === 'NOK') {
                            $('div.addtocartfromurl-saved-cart-messages').addClass('addtocartfromurl-saved-cart-messages-alert alert alert-warning').text('{l s='There was a problem deleting the cart. Please, try again.' mod='addtocartfromurl'}');
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //$('button#submitDeleteSavedCart').removeAttr('disabled').removeClass('disabled');
                        $('button#submitDeleteSavedCart').removeAttr('disabled');
                        console.log(XMLHttpRequest);
                        if (textStatus !== 'abort') {
                            alert("TECHNICAL ERROR: unable to delete cart  " + card_number + " \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
                        }
                    }
                });
            } else {
                $('button#submitDeleteSavedCart').each(function(){
                    $(this).removeClass('active');
                });
            }
        }

 

Immagine 2022-03-03 103925.png

Link to comment
Share on other sites

Hi,

The problem is from here:

$('div.addtocartfromurl-saved-cart-messages').addClass('addtocartfromurl-saved-cart-messages-alert alert alert-warning').text('Si è verificato un problema durante l' eliminazione del carrello. Ti invitiamo a riprovare più tardi.');

Exactly from here:
'Si è verificato un problema durante l' eliminazione del carrello. Ti invitiamo a riprovare più tardi.'

Replace with

'Si è verificato un problema durante l\' eliminazione del carrello. Ti invitiamo a riprovare più tardi.'

Because of that quotation mark, the javascript code is no longer ok, because of it, it closes the string. You can add \ or replace it with ".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...