I have the following code that loads a login page into my single page web site when a user clicks on the login button. The href in this case calls a MVC4 controller and this returns a partial view with the HTML.
$('#loginLink')
.click(function () {
var $link = $(this);
var href = $link.attr('data-href');
$('#article').load(href);
}
return false;
});
But I also need to have some additional Javascript loaded from the server. Can someone tell me how I can do this as the page is loaded. Rather than at the start when all my javascript is loaded into the browser.
Here's my MVC4 code for the login page:
@model WebUx.Models.LoginModel
<section id="content" class="grid_9">
........
</section>
@Scripts.Render("~/bundles/jqueryval")
Here's the C# code for the javascript bundle:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
Even if the scripts render then it seems they are not added to the web page when I check with the chrome developer tools. Ideally I don't want them to be inline. I would like them loaded as normal js that the browser can check against its js cache.