You should evaluate this code like this
eval("("+response+")");
OR
If your answer contains both html and javascript code, you should do it like this
$.ajax({ url: "/snippets/js-in-ajax-response.html", context: document.body, success: function(responseText) { $("#response-div").html(responseText); $("#response-div").find("script").each(function(i) { eval($(this).text()); }); } });
Bhavik patel
source share