So basically I have a page the renders rows from a database
{% for q in rows %}
<tr>
<td>Column 1</td>
<td>
<a href="#modalUpload" data-toggle="modal" data-question-id="{{q.id}}">Upload</a>
</td>
</tr>
{% endfor %}
The second column is a link to a modal page
<div class="modal fade" id="modalUpload" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-content">
{{ dropzone.create(url_for('uploadImages', qid=??????)) }}
{{ dropzone.config(redirect_url=url_for('examQuestions', examid=examid)) }}
</div>
my javascript code
$('#modalUpload').on('show.bs.modal', function(e) {
var qid = $(e.relatedTarget).data('question-id');
});
What I need is to send the qid
variable to the url_for contents... I know I can't do it because the page is already rendered before this js code is executed.. my question is, can I render the modal after this page is executed? I tried with ajax and flask server-side sending new data to my page, and then replacing the html contents, but I can't get it to work.. code are being sent as text not code
Edit: I know with dynamic contents I can load html code, but how is this supposed to work with my code? Here is my code that instead of returning a jinja code it returns a text
$(document).ready( function() {
$('#modalUpload').click(function() {
$.ajax("{{ url_for('gnp', qid=qid) }}").done(function (reply) {
$('#modalcontent').html(reply);
});
});
});
Reply is
{{ dropzone.create(url_for('uploadImages', qid=10)) }}
{{ dropzone.config(redirect_url=url_for('examQuestions', examid=examid)) }}
which is shown in my modal as text instead of being run by jinja2