javascript - Evaluating JS from an Ajax response using JQuery -
i have ajax form submit, , response contains 2 divs, 1 containing html content , other containing dynamic javascript in script tag.
i'm submitting form , receiving response ok, can't seem javascript evaluate. i've put alert inside never fires. code using submit form:
$("#categoryformsubmit").live("click", function(event){ event.preventdefault(); var action = this.form.action + '?_eventname=' + this.name + 'ajax'; var params = $(this.form).serialize(); var xhr = $.post(action, params, function(response) { var responsedom = $(response); var contentdata = $('#content', responsedom).html(); var javascriptdata = $('#javascript', responsedom).html(); $('#content').html(contentdata); $('#javascript').html(javascriptdata); }, 'html'); });
in response trying convert response data dom object , parse out content , javascript, , insert them existing dom. content replacement works fine, nothing seems working javascript. can't evaluate. how should doing this? imagine shouldn't trying insert dom am.
there no need manually parse response , separately add html , js page. jquery detect scripts inside of markup attempt add dom , handle proper addition , execution of them.
Comments
Post a Comment