Skip to content Skip to sidebar Skip to footer

Putting Javascript Variable Into Play Function

For my public files, I usually use: @routes.Assets.at('data/table.txt') in regular html However, I have a javascript with the variable link var file = 'table.txt'//This changes de

Solution 1:

  1. It's much more... comfortable (who'd guest? :)) just when you are using assets' routes you are able to switch ie. between CDN's much faster. If you'll put hardcoded URL's everywhere you'll need to fix all of them when you'll change your app's location.
  2. There are some possibilities also with common JavaScript, you can for an example write the route's value to JS' someSpecificRoute = '@routes.Assets.at(link)'; and than use it in your script

    $('#mydiv').CSVToTable(someSpecificRoute);
    

    maybe you can also use javascriptRoutes however you'll need to decide yourself. In general using it is good idea when you are planning to use them more than once or twice.

  3. Finally you can just use a hardcoded path and common JavaScript techniques for sending additional params. In such case I can only advice that for the security reasons it will the best if you'll validate if passed arguments fits allowed type and/or range.

Post a Comment for "Putting Javascript Variable Into Play Function"