javascript atob returning 'String contains an invalid character'

后端 未结 3 1106
抹茶落季
抹茶落季 2020-12-13 09:58

I have an AJAX call getting info out of the Github API. It is returned in base64 encoding but when i try to decode it I get the aforementioned error.

Has anyone run

3条回答
  •  醉梦人生
    2020-12-13 10:27

    atob breaks due to the newlines in the response. Remove them to get your code to work:

    function addSVGToPage(SVGToAdd) {
        var entry, decodedEntry;         // <-- What is this doing here? It's unused.
        makeAJAXCall(SVGToAdd, function (returnedJSON) {
            console.info(window.atob(returnedJSON.data.content.replace(/\s/g, '')));
            //                                                ^^^^^^^^^^^^^^^^^^^
        });
    }
    

提交回复
热议问题