Im using Django, the view that returns json object, has the next code:
def searchTourDBEsp_view(request):
print 'llamamos search ESP'
dataTourEsp = TourEsp.objects.raw('SELECT * FROM appMain_tour where idTour=1')
dataTourEspSer = serializers.serialize("json",dataTourEsp)
return HttpResponse(json.dumps(dataTourEspSer),content_type='application/json')
as you can see i have to make a serialization to the database consult.
In my template i need to have access to the data that is returned.
$.ajax({
type:"POST",
url: '{% url "url_searchTourEsp"%}',
data: data1,
success: function(jsonAjaxResult){
console.log("Ajax ok");
console.log("nombre");
console.log(jsonAjaxResult);
console.log(jsonAjaxResult[0]);
},
error: function(data){
alert("Got an error, Pleas conctact the Administrator");
alert(data);
}
});
The jsonAjaxResult object has all the information that i need, but it is an array of string. The content of jsonAjaxResult is the follow
[{
"fields":
{
"Monday": true,
"restrictions": "No kids",
"name": "Yate Mar",
},
"model": "appMain.touresp",
"pk": 1
}]
and the only way to have access to the data is typing
console.log(jsonAjaxResult[0]);
that has as result [
does someone know how to have access to the information like:
jsonAjaxResult['restrictions'];
but if i type this, the result is undefined
jsonAjaxResult[0]['restrictions']You need to iterate over the array and query the restriction of each element.