Reputation: 311
I have came across a question when I am doing Intersystem Cache Server Page with Javascript.
Here is my Sample Code:
Case 1:
<script language="Javascript">
function test1(){
var val = 0;
#server(..Set())#;
alert(val);
}
</script>
<script language="Cache" method="Set">
Write "val = 50;"
</script>
In this case, when the function test1()
is called, the value = 0 and it is a local variable.
Case 2:
<script language="Javascript">
function test1(){
#server(..Set())#;
alert(val);
}
</script>
<script language="Cache" method="Set">
Write "val = 50;"
</script>
In this case, when the function test1()
is called, the val = 50 and value is now a global variable.
So my questions are:
Upvotes: 1
Views: 446
Reputation: 2553
Actually you can set a variable in this manner but it has to be in a global scope not in a function scope. If you remove var val=0;
from your function it should work. It's better to just return values instead of using hardcoded variable names to avoid problems with scoping, duplicate naming etc.
Upvotes: 1
Reputation: 3205
You can't just generate javascript code on server side this way. You can return one value from this method and get it back in Javascript.
<script language="Javascript">
function test1(){
var val = #server(..Set())#;
alert(val);
}
</script>
<script language="Cache" method="Set">
quit 50
</script>
Upvotes: 2