I am currently working on an ajax function that retrieves a value from a Django function. My goal is to make this output global so that I can utilize it in a select dropdown menu. Below is the snippet of my code:
$(document).ready(function ()
{
function AjaxCall(HandleData)
{
return $.ajax({
url: "/evidence_values/",
type: "post",
data: {'evidence':document.getElementById('evidence').value},
success: function(data){ HandleData(data);}
});
}
$("#save").click(function(){
AjaxCall(function(output){filter_data = output});
});
function CallAjax(DataHandle)
{
return $.ajax({
url: "/get_evidence_items/",
type: "post",
success: function(data){DataHandle(data);}
});
}
$("#evidence_selected").click(function(){
CallAjax(function(output){items_data = output});
});
In another part of index.html, you will find the select dropdown menu as shown below:
<select name="evidence_selected" id="evidence_selected" style="margin-right:20px;color:#5c89db;margin-top:20px;margin-left:40px;height: 2em;border-radius: 3px;">
<option value="selectedvidence" id="selectedvidence"name="selectedvidence">Select Evidence Number</option>
{% for item in items %}
<option value="{{item.evidence}}">{{ item.evidence }}</option>
{% endfor %}
<option id="new"value="new">New</option>
</select>