0

about a website which runs with chicagoboss and otp19, I have three files: index.html, config.js and zeus_config_controller.erl, those 3 files have been working just fine before, but after I copy those files to a new server and run the website at this new server, then the problem occurs.

Seems that chicagoboss cannot connect the request from js file to erl file anymore, the log shows:

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. Can anyone please suggest if I need to do any configuration somewhere please ? I didnt do any configuration related to this chicagoboss yet.

thank you so much.

zoro
  • 333
  • 3
  • 13
  • Post a tree of your directory structure for your project. Post your controller. Post your js file. – 7stud Feb 24 '18 at 12:14
  • Also open the javascript console for your browser and post any errors that are listed there. – 7stud Feb 24 '18 at 12:50

1 Answers1

0

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.

7stud
  • 46,922
  • 14
  • 101
  • 127