0

I have an AJAX request which successfully returns a string in the format of a list. (Done using flask)

$.ajax({
    type: 'POST',
    url: "{{ url_for('PatientDashboard') }}",
    data: {Date: dateText},
    dataType: "text",
    success: function (Data) {
        console.log(Data)
        var Data = Data
    }
});

The output in the console is a string of ["Item1", "Item2", "Item3"] which I need to manipulate by converting this into a list and iterating through.

The desired result is to be able to do this in my HTML code.

{% for i in AppointmentList %>
    <a href="#">{{ i }}</a>
{% endfor %}

Which should output a series of links of Item1, Item2, Item3 - all separate links.

In summary, how do I access the variable Data in the HTML part where I am able to use Jinja2 to manipulate it?

Thanks in advance.

EDIT:

Solved by passing variables through a flask render_template.

nx_prv
  • 127
  • 8
  • parse the string and store into array from the view side which goes to the particular url. – Mohit Harshan Feb 18 '19 at 09:54
  • @MohitHarshan please elaborate on this? I don't understand what that means. – nx_prv Feb 18 '19 at 09:56
  • Your server-side Jinja2 code **generates** HTML, it is not HTML itself, and it runs on the server before the browser gets a hold of the resulting HTML. You can't rerun your server-side code inside the browser after the browser gets more data with client-side JS. See the duplicate. – Quentin Feb 18 '19 at 09:58
  • where do you write your python code? – Mohit Harshan Feb 18 '19 at 10:21

0 Answers0