Reputation:
I am making an XMLHttpRequest that should return an mp3 file. However, it returns 'undefined
'. I am not getting any errors in the console (thought it would be a allow-content issue but this is a public API).
This is the jssfiddle and the code. Please note that I am not posting a valid API key so we should receive "ERROR: The API key is not available!
" instead of the mp3, but still not an undefined
.
https://jsfiddle.net/r0j9yojo/5/
<button onclick="doit()">doit</button>
function doit() {
var endpoint = 'https://api.voicerss.org/?key=testkey&src=test&hl=es-es';
var client = new XMLHttpRequest();
client.open('GET', endpoint, true);
client.onreadystatechange = function() {
if (client.readyState == 4 && client.status == 200) {
alert(client.readyState + '/' + client.status + '/' + client.responsetext);
}
}
client.send();
}
Upvotes: 0
Views: 375
Reputation: 558
The property of client
you are looking for is responseText
, not responsetext
(note the capitalized T).
In the future, use console.log(object)
(in your case console.log(client)
) to inspect an object through your browsers console, which is usually accessed with F12 or through the menu.
Upvotes: 1