I return HTML content with backend, including tags. But when i got the content from backend, it seems like it does not see(activate) the scripts.js file, although html content is fine. For example, if i change path to style.css, the page will change it appearance, tried the same way with JS file, but it didn't help.
How do i active javascript file provided inside <head>
tags, after returning whole html content from backend?
Asked
Active
Viewed 129 times
0

narayana raghavendra
- 21
- 2
- 7
-
It's not entirely clear from your description (and not helped by the fact you posted no relevant code) ...but are you talking about the response to an AJAX request? Why are you replacing your `` tag via AJAX? You really shouldn't be doing a whole-page replace. I suggest you maybe investigate the use of MVC's Partial Views feature. – ADyson May 10 '19 at 12:20
-
But if you're just talking about loading a script tag in the usual way...then if it's not working, you need to investigate properly - open your browser's Developer Tools, then load your page. Check for 1) any JavaScript errors in your Console, 2) whether the script file loads successfully in the Network tools (a 200 status next to the script file indicates it loaded ok, anything else is a problem) – ADyson May 10 '19 at 12:23
-
I open html file, there is a script that call method from the backend, backend returns html content. In this content i have – narayana raghavendra May 10 '19 at 13:06
-
"there is a script that call method from the backend, backend returns html content" ...so to be clear (again): you mean the script triggers an AJAX call to the backend? For security reasons, script tags returned in HTML delivered via AJAX are not executed (see [this](https://stackoverflow.com/a/4620099/5947043)). It could be used to inject malicious content. Better to load all the scripts you need when you first load the main page. And I'll repeat, there should be no need for this HTML returned via the AJAX call to replace your `` tag. – ADyson May 10 '19 at 13:16
1 Answers
-2
You could add something in the Body of your html that runs your script:
<script type="text/javascript" src="/your/script/here.js">
.....
.....
</script>
That should solve your Problem.

Prashant Pimpale
- 10,349
- 9
- 44
- 84

Alexander Hurtig
- 49
- 1
- 6