aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Sending Javascript from server to execute on client side. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Sending Javascript from server to execute on client side." Watch "Sending Javascript from server to execute on client side." New topic
Author

Sending Javascript from server to execute on client side.

samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Hello Ranchers
Is it possible to send some bunch of javascript function from server and then get them executed one ofter another on client side?I am aware of eval function which does this job but I am not sure as to what should be the parameter to eval if I am requesting to a JSP from client to get all those function which I need to get to get executed on client side. Do I need to write the code to extract the javascript code from the response and then do manupulation on response so as to get all the list of comma seperated JS functions which I can pass to eval ? Any white paper link will greatly be appreaciated.
Thanks
Samir
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

Of course it is. All the Javascript in your pages comes from the server already. So perhaps you could be more specific about what you actually want to achieve.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Without mentioning how the script is being fetched, no answer is possible. Is this using Ajax? JSP includes? What?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Hello Paul, Bear
Thanks a lot for the reply. I am going to fetch javascript there by making AJAX call to a JSP. This JSP is meant specifically for sending some information to the client in javascript array . Though I am not sure as to how I can access the ONLY the js function from the response and evaluate these
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use JSON?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

If you are using jQuery to do your Ajax for you (and have set the response type to HTML), any script blocks in the response will be automatically executed.

If you are doing your Ajax "by hand", you've got a big job ahead of you... You'll need to find all the script blocks yourself and cause them to be evaluated.
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
ahhhhh....All rt Bear...Thanks a lot for the kind help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending Javascript from server to execute on client side.
 
Similar Threads
calling jsp function inside html event
Ajax - how to tell client to render new page.
Can this Java code convert to Javascript code
Undefined on jQuery Ajax Request
Why to use eval function inside Javascript