通过Ajax调用加载html时为什么未下载脚本 [英] Why script isn't downloaded when loading html via Ajax call
问题描述
我用MVC编写.
我的UserControl仅在内部
已更新
I write in MVC.
I have UserControl that has inside only this
UPDATED
<div id="login-container">
<div id="login">
<script src="/Scripts/shared/Site.js" type="text/javascript"></script>
<input type="text" />
</div>
</div>
当我通过Ajax调用加载此控件时(我返回View("UserControl")),因此未下载脚本.解决该问题的唯一方法是编写
When I load this control through Ajax call(I return View("UserControl")), so the script isn''t downloaded. The only way to fix it is to write
$.getScript("Scripts/shared/Site.js")
之后
after
$("#container").html(UserControlHtml)
我意识到只有在通过Ajax调用加载UserControl时才会发生这种情况,但我不明白为什么.有人可以解释幕后发生的事情吗?我想了解为什么加载带有脚本的html不会下载脚本
谢谢
I realize that this happens only when I load UserControl through Ajax call, but I don''t understand why. Can someone explain what is going on behind the scene? I want to understand why loading html with script inside it doesn''t downloads the script
Thank you
推荐答案
.getScript("Scripts/shared/Site.js")
.getScript("Scripts/shared/Site.js")
之后
after
("#container").html(UserControlHtml)
("#container").html(UserControlHtml)
我意识到只有在通过Ajax调用加载UserControl时才会发生这种情况,但我不明白为什么.有人可以解释幕后发生的事情吗?我想了解为什么加载带有脚本的html不会下载脚本
谢谢
I realize that this happens only when I load UserControl through Ajax call, but I don''t understand why. Can someone explain what is going on behind the scene? I want to understand why loading html with script inside it doesn''t downloads the script
Thank you
^ ]可能会帮助您理解.
This[^] may help you understand.
这篇关于通过Ajax调用加载html时为什么未下载脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!