I used another way to load the javascript file specified on the html page:
First, I define some variables inside the <head></head> tags, so I call my javascript file:
<head> ... <script src="/static/js/jquery.js"></script> <script type=text/javascript> $(document).ready(function() { $link_subcat = "{{ url_for('load_subcategories') }}"; $link_cat = "{{ url_for('load_categories') }}"; }); </script> <script src="{{ url_for('static', filename='finances.js') }}"></script>
...
This is my javascript content: $ (document) .ready (function () {
$("#category").change(function() { $.ajax({ type: "POST", url: $link_subcat, data: {cat: $(this).val()}, success: function(data) { $("#subcategory").html(data); } }); }); $("input[name=type]").change(function() { $.ajax({ type: "POST", url: $link_cat, data: {type: $('input[name="type"]:checked').val()}, success: function(data) { $("#category").html(data); } }); }); });
This approach works for me.
Silas santiago
source share