In your addcode.js include the following code.
$(document).ready(function(){
$.ajax({url: "databasecall.cgi", success: function(result){
$("#ajaxElement").html(result);
}});
});
And your index.cgi should have jQuery Library loaded. It should look something similar to this...
<!doctype html>
<html>
<head>
</head>
<body>
<h1>Loading a CGI file via jQuery/AJAX</h1>
<!-- more content -->
<header id="pageHeader"><h2>This section is populated using jQuery/AJAX</h2>
<div id="ajaxElement"></div>
</header>
<!--more content -->
<!-- absolute or relative path to your jQuery Library. You can also use CDN from jQuery.org. I use npm to install mine. -->
<script src="/node_modules/jquery/dist/jquery.min.js"></script>
<!-- make sure your path to jQuery libray is correct -->
<script src="addcode.js"></script>
</body>
</html>