I am trying to pull a from via ajax on the “current.html”
The view that handles the form renders “form.html”
“current.html” is something like:
<script>
// ajax that pulls the form on a#get_form click
// fills up div#mod_post with the result
</script>
<a id="get_form" href="{% url to the view that handles the form %}">get form</a>
<div id="mod_post" style="display:none;">
{% include "form.html" %}
</div>
All good until here … the form is nicely retrieved and shown.
“form.html” is something like:
<script type="text/javascript" src="/the/script/that/should/handle/the/post.js"></script>
<form id="mod_form" action="" method="POST" enctype="multipart/form-data">{% csrf_token %}
<table class="form">
{{ form.as_table }}
</table>
<input class="submit" type="submit" value="modifica">
</form>
Only thing is that everytime when form.html is being rendered, it never contains the part:
<script type="text/javascript" src="/the/script/that/should/handle/the/post.js">
</script>
Am I doing something wrong here, obviously yes, but I cannot spot it.
Any feedback is welcome, thanks!
If you’re just straight dumping the HTML response via JavaScript, then that’s normal behavior. Your browser (i.e. all of them) auto-strips
<script>tags added to the page by JS via an arbitrary HTML string response as a security precaution.