Loading jQuery code (along with html) via Ajax or jQuery's post or get methods
Is it possible to load jquery code in addition to html via ajax or jquery's post or get methods? I am trying to build conditional gui element activation (based on user's input).
It doesn't make sense to create one file with all jquery code taking all the conditionality into consideration. Instead, my hope is that if jquery via ajax allows me to load jquery code as well, then I can furt开发者_C百科her reduce the jquery based code foot print and load the only code that is relevant conditionally generated elements (rather than the entire deeply nested tree conditionality).
From personal experience injecting html into the dom that includes script tags causes all sorts of issues.
However jQuery has a handy method called
$.getScript()
that will allow you to dynamically include a javascript file + a success callback to invoke any of the code within the script.
精彩评论