I've an ajax call in my html of a django application. How can I handle the returned object in javaScript if my python backend returns a list that includes python dictionary:
html:
$.ajax({
type: "GET",
url: '/api/check_variable/?name='+$("#foo").val()+'&stat='+stat_id,
data: "check",
success: function(response){
alert("response[2]);
}
)}
urls.py:
urlpatterns = [
path("check_variable/", views.api_for_class_checking, name="check_variable"),
]
views.py:
def api_for_class_checking(request, **kwargs):
return ['id1', 'id2',{'filabel': 'label F', 'svlabel': 'labelS', 'enlabel': 'labelEn'}]
In this case my html page alerts just Object as response[2]. How can I get the attributes of the returned object, like the value of 'filabel' e.g. ?
There is nothing wrong to your code because your ajax call returned an object:
{'filabel': 'label F', 'svlabel': 'labelS', 'enlabel': 'labelEn'}
If you want to alert an attribute of your returned data(for example: filabel) you can try this in your ajax call:
alert(`${response[2].filabel}`);
Or,
alert(`${response[2]["filabel"]}`);