我正在使用python
SimpleHTTPServer
在localhost
上投放测试页。
src
标记的空audio
。
<audio id="audio" src=" "></audio>
请求:
<script>
var request = new XMLHttpRequest();
request.open("GET", "http://127.0.0.1:8000/audio/song.wav", true);
request.responseType = "blob";
request.onload = function() {
if (this.status == 200) {
var audio = document.getElementById("audio");
var src = URL.createObjectURL(this.response);
audio.src = src;
audio.load();
audio.play();
}
}
request.send();
</script>
但XHR
加载失败。错误在哪里?