我正在尝试:

   $("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,请按照以下步骤格式化网址:

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”值的函数的帮助。

最佳答案

这是为我工作的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");
}});

09-07 18:09