Help needed: JSON request issue with XMLHttpRequest
var xhr = new XMLHttpRequest();
function elenco_studenti() {
var url = "/controller?action=student_list";
xhr.responseType = 'text';
xhr.open("GET", url, true);
xhr.onreadystatechange = print();
xhr.send(null);
}
function print(){
console.log(xhr.responseText);
}
It's strange, the console log doesn't show anything for this way of requesting JSON. But it works when using jQuery:
$(document).ready(function(){
$.ajax({
url: '/controller?action=student_list',
dataType: 'json',
success: function (data) {
console.log(data);
}
});
});
If you have any insights or can offer assistance, I'd greatly appreciate it. Thank you!