开发者

Why script isn't downloaded when loading html via Ajax call

开发者 https://www.devze.com 2023-02-08 00:53 出处:网络
I write in MVC. I have UserControl that has inside only this UPDATED <div id=\"login-container\"> <div id=\"login\">

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>

When I load this control through Ajax call(I return View("User开发者_C百科Control")), so the script isn't downloaded. The only way to fix it is to write

$.getScript("Scripts/shared/Site.js")

after

$("#container").html(UserControlHtml)

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


I think you may find that your issue is inside the usercontrol. you should change the following line:

<script src="/Scripts/shared/Site.js" type="text/javascript"></script>

to:

<script src="<%=Url.Content('~/Scripts/shared/Site.js')%>" type="text/javascript"></script>

that's my guess anyway..

0

精彩评论

暂无评论...
验证码 换一张
取 消