Call jQuery from ColdFusion

Is it possible to call the jQuery function from a ColdFusion switch statement? If so, how?

+3
source share
4 answers

Do you know that you mix client and server code? However, this is really not a problem:

<script language="javascript">
    <cfswitch expression="#n#">
      <cfcase value="test1">
        $.something1()
      </cfcase>

      <cfcase value="test2">
        $.something2()
      </cfcase>
    </cfswitch>
</script>
+6
source

No. ColdFusion runs on the server. jQuery runs on the client (in the browser). You can conditionally output (depending on which case you click) JavaScript code that will call the jQuery function.

+3
source

β„– . , CF JS , .

, JavaScript , JavaScript- .

, - , ,

 $(document).ready(function(){
   // Your code here
 });
+2
source

Nick is certainly correct in his answer as one of the possible solutions. However, for me, a cleaner approach might look like this:

var species = '#species#'; // convert cf variable for use in javascript

switch(species){
  case "cat":
      // cat code
  case "dog":
      // dog code
  case "zebra":
      // zebra code
}

Using this approach, you prevent the server and client code from intertwining in the same way, which leads to more readable code.

+1
source

Source: https://habr.com/ru/post/1734926/


All Articles