1

私はこれを試しています:

   $("i.icon-play-circle").click(function(){
        var word = "你好";
        var url = 'http://apifree.forvo.com/key/XXXXXXXXXXXXXXXXXXXXXXXXXXX/format/json/action/standard-pronunciation/word/'+encodeURI(word)+'/language/zh';
        $.ajax({
            url: url,
            crossDomain: true,
            dataType: "jsonp",
            success: function (i,item) {
                alert(item);
            },
            error: function () {
                alert('foo');
            }
        });
    });

ファイアバグコンソールでこのエラーが発生しました:

SyntaxError: invalid label
[Break On This Error]   

{"items":[{"id":1967282,"addtime":"2013-01-21 23:35:31","hits

zh?cal...0549189 (line 1, col 1)

アップデート:

jsonpを取り戻したい場合は、URLを次のようにフォーマットする必要があります。

apifree.forvo.com/key/XXXXXXX/format/json/ callback / your_function_here / action / standard-pronunciation /word/你好/language/ zh

結果:

pronounce({"items":[{"id":436,"addtime":"2008-03-16 10:40:22","hits":4346,"username":"geneboy","sex":"m","country":"China","code":"zh","langname":"Mandarin Chinese","pathmp3":"http:\/\/apifree.forvo.com\/audio\/2i253j1l2e2m1b2i2f3q2d2g2f341k2q1f3h2g1b3m223i342b2q3k28323n2732372e1b1o393k2k1m1i2q3m353q253l36371l3k3a3q3d271h3133342o263g3223_3m2d2p2f2d1f2k3n1h3i3g2q263f293e1b253g1i2f2h1t1t","pathogg":"http:\/\/apifree.forvo.com\/audio\/3b2625373d3f2n1j233d2b211i3j3p3g1b1j1m312i3j2f261l2e2n383k371i1m3a3l292o3k2h29293h3q3c3f362h2k2h271m3i312o211h3m3g1h3e351m2n2d27_293q2c2l1m343a2q26343a391k1p3m1o2a2q333f35371t1t","rate":5,"num_votes":5,"num_positive_votes":5}]})

「pathmp3」値を出力する関数を作成するためのサポートが必要です。

4

1 に答える 1

1

これが私のために働いたajaxコードです:

    word = "你好"
    var url = 'http://apifree.forvo.com/key/XXXXXXXXXXXXXXXX/format/json/callback/pronounce/action/standard-pronunciation/word/'+encodeURI(word)+'/language/zh';
    $.ajax({
        url: url,
        jsonpCallback: "pronounce",
        dataType: "jsonp",
        type: "jsonp",
        success: function (json) {
       var mp3 = json.items[0].pathmp3;
       var ogg = json.items[0].pathogg;
   },
    error: function(){
        console.log("error");
}});
于 2013-01-26T14:37:39.533 に答える