0

Web アプリケーションで Google フォントを使用しようとしています。Googleフォントをロードするための私の呼び出しは次のとおりです:

$.get("https://www.googleapis.com/webfonts/v1/webfonts?key=xxxxxxx", function (result) {                                             
        var data = {};
        console.log(result);
        console.log($.parseJSON(result));
        data.items = $.parseJSON(result).items;
});

上記の呼び出しにより、3 つのターゲット ブラウザーで次の結果が得られます。

ファイアフォックス

console.log(result);               ========> JSON string
console.log($.parseJSON(result));  ========> Successfully parsed the json string
data.items = $.parseJSON(result).items; ===> contains all google fonts

イエ(9)

$.get callback is not executing.

クロム

console.log(result);               ========> Object
console.log($.parseJSON(result));  ========> null

上記の3つのブラウザすべてでGoogleフォントを使用する一般的な方法を教えてください。

4

1 に答える 1

0

Firefox、IE、および chrome で動作する一般化された呼び出しを見つけました。

$.ajax({
    url: "https://www.googleapis.com/webfonts/v1/webfonts?key=xxxxx",
    type: 'GET',
    dataType: 'JSONP',
    success: function (data) {   
      // data.items contains all google font-families name
    }
});

これが他の人に役立ちますように!

于 2013-01-10T06:36:21.780 に答える