We're Hiring!

Use javascript at web application.

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Use javascript at web application.

Postby dwj » Tue Jan 12, 2016 12:35 pm

Hi,

I was able to build a web application with OMERO.web. Now I want to add some JavaScript logic into the web page. For this I wrote a js-file and store it next to the html file.
When I load the web application at the client I can see the content of the html page, but the js-file is not loaded. The error at the client browser is:
GET http://localhost:8080/WebHWorld/media/javaScript.js 404 (NOT FOUND)

The html file looks like this:
Code: Select all
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="javaScript.js"></script>
    </head>
    <body>
   <form action="/WebHWorld/" method="get">
      <!-- MY CONTENT-->
   </form>
   </body>
<!html>


What do I need to change to load a javascript file?

Thanks!
dwj
 
Posts: 23
Joined: Mon Nov 16, 2015 10:46 am

SOLVED: Use javascript at web application.

Postby dwj » Wed Jan 13, 2016 7:36 am

I have solved the problem. I have to put the javafile not next to the html file but inside a 'static' directory at the project directory.
The file is now at: 'ProjectDir/static/{ProjectName}/js/javaScript.js

At the html I changed the script source:
Code: Select all
<script type="text/javascript" src="{% static 'WebHWorld/js/javaScript.js' %}"></script>


After these changes the jacascript is loaded.
dwj
 
Posts: 23
Joined: Mon Nov 16, 2015 10:46 am

Re: Use javascript at web application.

Postby atarkowska » Wed Jan 13, 2016 9:39 am

Hi,

That is correct. Please refer to Django documentation for more details https://docs.djangoproject.com/en/1.8/h ... tic-files/

Ola
atarkowska
 
Posts: 327
Joined: Mon May 18, 2009 12:44 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest