| 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: 56204
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 15357
|
|
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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
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
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
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
|
 |
 |
|
|
subject: Best practise to load javascript settings from server
|
|
|