My website is AJAX based and I need to make AJAX request which return sometimes JavaScripts ( <script>
elements). The jQuery documentation says that $.load
cuts the <script>
elements because of the html()
function. How do I keep the scripts and make them run when inserted in the code?
$.getScript()
will fetch scripts for you. Just give it the URL of the script to download, and it will (from the docs ):
Load a JavaScript file from the server using a GET HTTP request, then execute it.
You can always use good old usual $.ajax()
call and in the success:
us the document.getElementById("element").innerHTML = data
function.
edit: didn't test it, but $("#element").append(data)
should also work.
edit2: document.getElementById("pasteElement").innerHTML = $(data).find("#copyElement")
edit3: now i just tried that idea of mine and i am puzzled, too. im so sorry.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.