wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Best practise to load javascript settings from server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Best practise to load javascript settings from server" Watch "Best practise to load javascript settings from server" New topic
Author

Best practise to load javascript settings from server

Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
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.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

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

Joined: Sep 04, 2009
Posts: 32
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
 
Don't get me started about those stupid light bulbs.
 
subject: Best practise to load javascript settings from server
 
Similar Threads
Fire a trigger from an external application on database update
External Java classes referenced from GWT app's server package
Help with program structure
Help on Changing font.
Problems organizing a project