• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practise to load javascript settings from server

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys....
I am developing an application where the user inputs some data to a table.
The data is appended using javascript+jquery... Code places some hidden fields and populates a table....
And i have this code at an external javascript file...

The problem is that when i want the user to retrieve what he has put ,populating the table using server side script seems a waste of time and writing code again which i should change if i change something in the javascript...

So i thought to get a JSON response from my server and then call the javascript method to populate the table....
The problem is that i should place the javascript code in my page and not at an external file ,because at an external it wont be parsed...

Also i would like to get advices how to solve this problem....
thank youu
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Miltos Tereres wrote:So i thought to get a JSON response from my server and then call the javascript method to populate the table....
The problem is that i should place the javascript code in my page and not at an external file ,because at an external it wont be parsed...



Sorry, not understanding the issue. If you include external JS, it is parsed exactly the same as if it were on the page.

P.S. English sentences end with a single period -- not multiple periods.
 
Miltos Tereres
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the page is a jsp and i include a javascript i cant use jsp tags etc in my js.
Only in the page.
So cant put initial parameters.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include the part of the JavaScript code in the page that needs to be customizable. Include the rest of the code in the external JavaScript file. Both can interact.

Or you can make a backend page that produces a custom js file for that user.

Eric
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another option is to include these dynamic parameters as hidden fields on your JSP. Then you can just look those up via JavaScript as you need them.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or as a top-level JavaScript object that the loaded script can reference.

You see, there's no dearth of solutions.
 
Miltos Tereres
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or as a top-level JavaScript object that the loaded script can reference.

What do you mean?
Hidden fields is a solution... but i want them to be at the top of the page...

<script type=text/javascript>
var mydata=<here goes the function that outputs a javascript escaped json object>

</script>
<script type=text/javascript src="external_crap.js"></script>
........

Is this a good practise or not ?


Someone said to parse a custon external js file...But is this ok ?I think that it makes thinks more complex....
thank you
 
reply
    Bookmark Topic Watch Topic
  • New Topic