See if you can get the following example to work:
zeus/src/controller/zeus_config_controller.erl:
-module(zeus_config_controller, [Req]).
-compile(export_all).
index('GET', []) ->
{ok, []}.
get_data('GET', []) ->
{json, [{a, 1}, {b, 2}] }.
zeus/src/view/config/index.html:
<html>
<head>
<title>{% block title %}Config{% endblock %}</title>
<!-- jquery cdn: --!>
<script src="http://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<!-- zeus js: --!>
<script src="/static/js/myjs.js"></script>
</head>
<body>
{% block body %}
<div id="results">results</div>
<div><button id="button1" type="button">Click me</button></div>
{% endblock %}
</body>
</html>
zeus/priv/static/js/myjs.js:
function on_button_click() {
$.get("/config/get_data", function(data) {
$("#results").text(data.a + data.b);
});
}
$(document).ready( function() {
$("#button1").click(on_button_click);
});
Enter the following url in your browser:
http://localhost:8001/config/index
then click the button. What do you see? Any errors in your browser's js console?
14:12:25.360 [info] GET /config/function1/paramX [zeus] 200 98ms
14:12:25.404 [info] GET /config/function2/paramY [zeus] 200 108ms
Now there's no erl log between those two lines of logs as it used to
be.
When I enter http://localhost:8001/config/index
for my example above, I see the following output:
...
...
07:05:42.421 [info] GET /config/get_data [zeus] 200 40ms
07:05:42.435 [info] GET /config/index [zeus] 200 55ms
That doesn't make a lot of sense to me because nothing in my code explicitly sends a GET request to /config/get_data
. Then when I click on the button on the page, I see:
...
...
07:06:11.231 [info] GET /config/get_data [zeus] 200 26ms
...as expected.