There is a form with two drop-down lists and one button. By clicking on the button, the data is sent in the form of json, filtering is performed on the basis of this data, then the filtered data is returned to the client. However, instead of the filtered data, error 500 (Internal Server Error) is displayed. The following output is displayed in traceback: string indices must be integers . How to fix this error?
Representation:
function GetSelectValue() { var select_type = document.getElementById("type"); var type = select_type.value; var select_net = document.getElementById("net"); var net = select_net.value; var filter = JSON.stringify({type:type, net:net}); return filter } $(function () { $("#btn1").click(function () { var filter = GetSelectValue(); console.log(filter); $.ajax({ type: "GET", dataType: 'json', url: '/map/filter/', data: { 'filter': filter }, success: function (stations) { pointLayer.removeAll(); draw_point_layer(stations); }, error: function (xhr, status, error) { console.log(error); } }) }); }); <body> <div name="infoDiv" id="infoDiv" class="esri-widget"> <!--<b>Filter by geometry</b><br/><br/>--> <label for="net">Π‘Π΅ΡΡ:</label> <select id="net" class="options"> <option value="INTERMAGNET">INTERMAGNET</option> <option value="IMAGE">IMAGE</option> <option value="EISCAT">EISCAT</option> <option value="MACCS">MACCS</option> <option value="CARISMA">CARISMA</option> <option value="CANMOS">CANMOS</option> <option value="AUTUMNX">AUTUMNX</option> <option value="USGS">USGS</option> <option value="AMN">AMN</option> <option value="DTU">DTU</option> <option value="ENIGMA">ENIGMA</option> <option value="EMMA/PLASMON">EMMA/PLASMON</option> <option value="Japan Meteorological Agency">Japan Meteorological Agency</option> <option value="GFZ">GFZ</option> <option value="Italian Magnetic Network">Italian Magnetic Network</option> <option value="Mid-continent Magnetoseismic Chain">Mid-continent Magnetoseismic Chain</option> <option value="Russian Arctic and Antarctic Magnetometer">Russian Arctic and Antarctic Magnetometer</option> <option value="Finnish Meteorological Institute">Finnish Meteorological Institute</option> <option value="Swedish Institute of Space Physics">Swedish Institute of Space Physics</option> <option value="BAS">BAS</option> <option value="Π ΠΎΡΡΠΈΠΉΡΠΊΠΎ-ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠΈΠΉ ΡΠ΅Π³ΠΌΠ΅Π½Ρ Π³Π΅ΠΎΠΌΠ°Π³Π½ΠΈΡΠ½ΡΡ
Π΄Π°Π½Π½ΡΡ
">Π ΠΎΡΡΠΈΠΉΡΠΊΠΎ-ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠΈΠΉ ΡΠ΅Π³ΠΌΠ΅Π½Ρ Π³Π΅ΠΎΠΌΠ°Π³Π½ΠΈΡΠ½ΡΡ
Π΄Π°Π½Π½ΡΡ
</option> <option value="all" selected>Π²ΡΠ΅</option> </select> <label for="type">Π’ΠΈΠΏ:</label> <select id="type" class="options"> <option value="station">ΡΡΠ°Π½ΡΠΈΡ</option> <option value="observatory">ΠΎΠ±ΡΠ΅ΡΠ²Π°ΡΠΎΡΠΈΡ</option> <option value="all" selected>Π²ΡΠ΅</option> </select ><br/><br/> <button id="btn1" class="esri-button" id="clearFilter" type="button"> ΠΡΠΈΠΌΠ΅Π½ΠΈΡΡ </button> </div> </body> views.py
from django.shortcuts import render from django.views.generic import TemplateView from .models import Station from django.http import HttpResponse from django.core import serializers def filter(request): if request.GET: filter = request.GET.get('filter') type = filter['type'] if type == 'all': stations = serializers.serialize('json', Station.objects.all()) else: stations = serializers.serialize('json', Station.objects.filter(type=type)) return HttpResponse(stations, content_type='application/json')