Forvo API and select the pathmp3 from the xml with jquery





I am trying to use the Forvo API to increase the pronunciation database of www.Audioramio.com - The pronunciation atlas.


My aim is simple, I need to request from Forvo all the pronunciations for a single word and select only the one I think is the best.

The xml is divided into "item" and for each of these there is an "id" with a number that uniquely identifies the contribution. I need to loop through each "item" and select the one "id" I like the most. Then I need to create an audio frame in html using "pathmp3", which is a temporary link to the mp3 file from Forvo.


Below is the jquery function I created.



$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://ift.tt/1ASXvkr",
dataType: "xml",

success: function(){
$(xml).find("item").each(function() {
if ($(this).find("id").text()*1 == 2525946) {
$("#test").append('"<audio controls src="' + $(this).find("pathmp3").text() + '"></audio>')
};
});
},

error: function(){
document.write("error");
}
});
});


XXX is the API key I got from Forvo.


On my page I have an empty div with id="test", where I would like to append the audio frame. However, the code above always return the error message. Could you please give me some suggestions on how to improve it?


Thanks.


No comments:

Post a Comment