Question
· Mar 19, 2020

[JavaScript] Accessing server function/variable in JS file

Hi everyone,

I have a javascript function in *.js file. This function has to access to variable set by server.

I've tried setting the variable in *.js like this;

function dummy(){

var myText = '#(myText)#';

}

However it seems like the webserver doesn't understand this coding convention. The js file sent back to client set myText in dummy() with the hard-value #(myText)#. It's not the value of myText variable in server side.

I know I can achieve this by putting dummy() directly in csp file. However I have to put dummy() in separated file, so that other files can use it.

My current work-around is putting dummy in a separated *.csp file. This file acts as common javascript library for my product. And other files which want to use dummy() will have to csp:include it.

My questions are:

1. Is there any way to access server side variable from function put in *.js file?

2. Is there any drawback with my work-around (by putting dummy in pseudo javascript-csp file)?

Discussion (3)0
Log in or sign up to continue