Looking for advice on improving my script to fetch JSON data from a server file using AJAX. I am struggling with organizing it into a functional structure.
Below is the current implementation:
function getJSON (file) {
var request = AjaxRequest();
var json = "";
request.onreadystatechange = function () {
if(request.readyState == 4 && request.status == 200) {
json = JSON.parse(request.responseText);
}
}
request.open("GET", file, false);
request.send();
return json;
}
Although the function meets my requirements, I have received feedback advising against passing 'false' as an argument in the AJAX request due to potential blocking issues. This leaves me unsure about the correctness of my approach. Any suggestions on how I can improve this function? Should I make any changes, and if so, what modifications would be appropriate?