I have a requirement of including a .js file (more jQuery code) at a run time in a currently working jQuery script. For example, if my page gets authenticated, then I want to include a particular script file. I want to do this in ASP.Net MVC.
Is there a way to do this? If so, what path do I give when calling that file?
I googled $.getScript('file_path'); but my page is getting refreshed in a loop, I don't why! Maybe I'm doing something wrong in path.
Any help would be much appreciated! Thank you.
$.getScript()is exactly what you need. We can't help you with the refreshing problem without seeing your code, though.~in a JS code directly, as it's a MVC construct. You need to use a relative path, eg$.getScript('/basefolder/foo.js');xhr.onreadystatechange = function (e) { if (xhr.readyState === 4 && xhr.status == 200) { $.getScript(xhr.responseText); } else if (xhr.readyState === 4 && xhr.status == 403) { location.href = '/Home/Auth'; } };while "xhr.responseText" would reply as "/Scripts/content.js" but no success, I think path is being a issue.