This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending Javascript from server to execute on client side.  RSS feed

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22476
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66187
149
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without mentioning how the script is being fetched, no answer is possible. Is this using Ajax? JSP includes? What?
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use JSON?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
149
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahhhhh....All rt Bear...Thanks a lot for the kind help
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!