Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
GET request works in development, not in production

I have written the following script that should run a GET request to a specific URL when a set of checkboxes are ticked on and off. It works perfectly locally but in Production, I get a 404 response.

Any idea why and how to fix it?

/**
* Remove all child nodes from an element
* @param {Object} element The element to empty
*/
function empty (element) {
    var children = Array.prototype.slice.call(element.childNodes);

    children.forEach(function (child) {
        element.removeChild(child);
    });

}

function toggleItem(toggler, itemType, itemUrl, itemState, itemSource) {
    let outputDiv = toggler.parentNode.querySelector('.theme-park-item-toggler-output');
    empty(outputDiv);

    let xhr = new XMLHttpRequest();
    xhr.open('GET', itemUrl);
    xhr.send(null);

    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) { // 4 means "Done"
            if (xhr.status === 204) { // 204 means processed successfully with no content returned
                console.log('success');

                if (itemState == true) {
                    let img = document.createElement('img');
                    img.src = itemSource;
                    outputDiv.appendChild(img);
                }
            } else {
                console.log('Failure to toggle');
                toggler.toggleAttribute('checked');
            }
        }
    };
}

document.addEventListener("turbo:load", function() {
    document.querySelectorAll('.theme-park-item-toggler').forEach(function(the_toggler) {
        the_toggler.addEventListener('change', function(e) {
            toggleItem(the_toggler, the_toggler.dataset.type, the_toggler.dataset.url, e.target.checked, the_toggler.dataset.source);
        });
    });
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda