Ashan77 Ashan77 - 1 year ago 101
jQuery Question

How to execute server returned javascript on client

I make an ajax call to a server and the server returns javascript and jquery code such as

$('someclass').html('<form id='billform'>......</>');

How do I execute this on the client side?

Answer Source

You could put that code inside a script tag and append it to the body This procedure is described best here:

However, it is not recommendet to simply execute some javascript which is loaded via ajax. I would recommend to work with events that would trigger this code which is on your page already.

$.get('/sumUrl', function(data) {
  switch(data.action) {
    case 'event1':
      //do sth.
    case 'event2':
      // do sth. else