I'm trying to get some data into a variable to use in a template. I've used <?php file_get_contents(...)
in a file called get.php
as a proxy to avoid cross-origin issue.
The code below works, but gives a warning that 'async' : false
is deprecated. However when I change it to true
it returns null.
What am I missing please? What is the correct, modern approach to achieving what I'm trying to do?
$(document).ready(function(){
var json = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': 'get.php',
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
console.log(json);
});