asp.net mvc - JavaScript/jQuery doesn't work on Editor/Display templates loaded with Ajax -
i created editor , display templates entire object downline.
now 1 of inner objects' text boxes should date-picker.
the thing it's loaded after initial loading using ajax, , included scripts don't work.
i tried include following script on bottom of template, script renders nothing:
@styles.render("~/content/themes/base/css") @scripts.render("~/bundles/jquerytimepicker") <script type="text/javascript"> alert('dddddddddddddddddddddddddd'); $('.time-picker').timepicker(); </script> in code abve added dummy alert prove script isn't running, makes question simpler: "how run scripts templates , partial views?".
i tried include scripts in section define in outer page, doesn't work, templates , partial view cannot include sections design (read this).
it doesn't work because js attaches timepicker html runs @ document.ready, content loaded via ajax loaded after document.ready
so need call method attaches timepicker again after ajax request has completed
you can try this:
$(document).ajaxcomplete(function(event, xhr, settings) { alert('an ajax request completed'); $('.time-picker').timepicker(); });
Comments
Post a Comment