您必须像这样评估该代码
eval("("+response+")");要么
如果您的回复同时包含html和javascript代码,则您必须这样做
$.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()); }); } });


