I have a json file which I have been using in my project in this structure
<script src="js/main.js"></script>
<script>
var data = {"bills":[{"id":1,"name":"DStv","reference":"SmartCard Number","logo":"bill\/logo\/24Io6IqObQ8ddi5.jpg","active":1,"lifestyle":0},{"id":3,"name":"GOtv","reference":"IUC Number","logo":"bill\/logo\/mCNl5X1ZCfph4kg.jpg","active":1,"lifestyle":0},{"id":6,"name":"Startimes"...
</script>
<script src="js/bill.js"></script>
<script src="js/airtime.js"></script>
As you can see from the above example, the json file have already been passed to a data variable... of which I have other external javascript file placed under it.
Meanwhile, the json file is now generated/accessible from a link and I was told to use ajax to get the json data into the project.
I have this code in my main.js file, I have the below code but its not accessible in the bills.js file
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://example.com/bills/resources",
success: function(result)
{
data = result;
loadData(result);
}
});
});
window.result = result;and accesswindow.resultfrom anywhere.