3
I need to play an audio in the execution of the excerpt below, where it displays the data found in a query:
// Verifica se o Ajax realizou todas as operações corretamente
if(req.readyState == 4) {
if (req.status == 200) {
// Resposta retornada pelo PesquisaRomaneio.php
var resposta = req.responseText;
// Abaixo colocamos a(s) resposta(s) na div resultado
document.getElementById('resultado').innerHTML = resposta;
// Toca audio se encontrou
var snd = new Audio("../images/alert.mp3");
snd.play();
} else {
document.getElementById('resultado').innerHTML = "Erro: " + req.status;
}
setTimeout(buscarRomaneio, segundos * 1000);
}
I tried to use the code below but did not execute. How can I fix this?
var snd = new Audio("../images/alert.mp3");
snd.play();
What is your browser? Tested in other browsers?
– Victor Stafusa
Make sure the audio is in the folder
images
?– Victor Stafusa
I tested on FF, Chrome, Opera and IE. None worked. The audio is in the images folder, for testing... I tried to drop it at the root, it didn’t work either.
– Diego
It works if you put in some folder that doesn’t start with
..
?– Victor Stafusa
no, I put in the folder that is the js: var snd = new audio("Alert.mp3"); and still did not play...
– Diego