Home Can't connect to JSON file using AJAX
Reply: 0

Can't connect to JSON file using AJAX

user1377
1#
user1377 Published in July 16, 2018, 8:33 pm

I'm making a javascript web app that takes the user's input about what font the want to check out from the google fonts API. I can't seem to connect to the google fonts api. I'm using the default code they have on their developer site.

https://developers.google.com/fonts/docs/developer_api

I'm trying to connect to this JSON file here

https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyCKDRrItgVcxrwi8AZwgqMnK4hyEC5tCoY

My AJAX code

function getFont(fontUrl) {

    var googleFontAPI = "https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyCKDRrItgVcxrwi8AZwgqMnK4hyEC5tCoY";

    $.getJSON(googleFontAPI, function (data) {
        var apiUrl = [];
        apiUrl.push('https://fonts.googleapis.com/css?family=');
        apiUrl.push(anonymousPro.family.replace(/ /g, '+'));
        if (contains('italic', anonymousPro.variants)) {
            apiUrl.push(':');
            apiUrl.push('italic');
        }
        if (contains('greek', anonymousPro.subsets)) {
            apiUrl.push('&subset=');
            apiUrl.push('greek');
        }

        // url: 'https://fonts.googleapis.com/css?family=Anonymous+Pro:italic&subset=greek'
        var url = apiUrl.join('');
        console.log(url);
    });
}

When I try to run the code it returns this error message

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338078 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO