#2814 Implementing Javascript in Fantom

arm Thu 27 Aug 2020

Dear All

I am a newbie to fantom and have quite good experience in programming c# and javascript. I have been trying to implement some functionalities in the webpage .I used the feature of Fantom WebApp. I would like to implement external JavaScript file into my webapp and host it in the localhost server.

I tried implementing ,but it says


Uncaught SyntaxError: Unexpected token <


My Objective :To read a text(text input from jquery file and hence to inculde the jquery dependencies) from the fan file ,(Fantom Webapp) and show it up in the web page. ie

tesWEbApp.fan

script file import
call the Jquery/Js file with the parameters from the fan file 
res.out.print (<div id='datafromJquery'></div>)

Also I would like to know the significance of pod, in the JavaScript implementation.

It would be really helpful if anyone could share me some good examples(step by step - other than in the js )/recorded videos for better clarification.

TIA

SlimerDude Mon 31 Aug 2020

Hi arm,

Do I understand correctly that you just want to run jQuery and Javascript on a dynamically generated HTML page, and NOT use Fantom or domkit in the browser?

Then you'll need to set up a Fantom web server to serve up static JS files (jQuery et al) and your dynamically generated HTML pages.

The first half of this article should walk you through serving server side rendered web pages:

Create a Mini Web Application with Wisp

http://www.alienfactory.co.uk/articles/create-a-mini-web-app-with-wisp

Then to serve up static files, you can use web::FileWeblet in your onGet() method.

arm Tue 22 Sep 2020

Hi Thanks for the reply

I can emulate the page .But cannot load my static files using web::FileWeblet

Can u help me with some sample files

Login or Signup to reply.