Giter Site home page Giter Site logo

Comments (5)

ms-dc avatar ms-dc commented on July 19, 2024 1

Por nada! Consegui fazer a requisição, valeu Thiago 👍

from dicio-api.

ThiagoNelsi avatar ThiagoNelsi commented on July 19, 2024

Opaa, boa noite! Como está fazendo a request? Vou tentar reproduzir o erro aqui

from dicio-api.

ms-dc avatar ms-dc commented on July 19, 2024

Estava tentando fazer a requisição por AJAX

from dicio-api.

ms-dc avatar ms-dc commented on July 19, 2024

Segue a função que estou tentando utilizar:

function openDicionario() {

    var selectedText = window.getSelection().toString();

    if (selectedText.trim().split(' ').length > 1) {
        $.fancybox.open(document.getElementById('erroDicionario'));   
    }
    else {
        $.fancybox.open(document.getElementById('dicionario'));        

        $('.container__dicionario-title').text("Significado para: " + selectedText);

        $('.box__dicionario').empty();

        $('.box__dicionario').html('<br /><div class="loader center"></div>');

        $.ajax({
            type: "GET",
            url: "https://significado.herokuapp.com/" + selectedText,
            success: function (response) {
                var definitions = loopThrough(response[0]);
                $('.loader').hide();
                if (definitions.length > 0) {
                    definitions.forEach(fillIn);
                }
                else {
                    $('.box__dicionario').append(html);
                    var html = "<p class='box__dicionario-descricao'>Nenhum resultado encontrado";
                    $('.box__dicionario').append(html);
                }

            },
            error: function (e) {
                $('.loader').hide();
                $('.box__dicionario').append(html);
                var html = "<p class='box__dicionario-descricao'>Nenhum resultado encontrado";
                $('.box__dicionario').append(html);
            }
        });

    }    

    function loopThrough(data, timesToTry = 5) {
        var keys = Object.keys(data);
        for (var k of keys) {
            // console.log("valor",k);
            if (k === "meanings") {
                if (typeof data[k] === "object") {
                    var substantivos = Object.keys(data[k]);
                    if (substantivos.length > 0) {
                        return data[k][substantivos[0]];
                    }
                }
            }
        }
    }
    
    function fillIn(item, index) {
        var html = "<p class='box__dicionario-descricao'><strong>" + (index + 1) + "</strong>. " + item.definition + "</p><p class='box__dicionario-linha'></p >";
        $('.box__dicionario').append(html);
    }
}

from dicio-api.

ThiagoNelsi avatar ThiagoNelsi commented on July 19, 2024

Corrigido, obrigado por reportar!

from dicio-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.