-
Гость
Ошибка типа: data.forEach не является функцией
Сообщение
Гость »
Это мой код:
Код: Выделить всё
$.ajax({
url: "some_url/",
type: "GET",
dataType: "json",
success: function(data){
console.log(data);
data.forEach(function(element){
console.log(element);
});
}
});
I get the error that for each does not work on the
variable. However, when I log
to the console, I get
Код: Выделить всё
[{"model": "app.mdl", "pk": 1, "fields": {"name": "test", "rank": 1}}]
This is clearly an array and iterable, so I don't get what exactly is wrong.
EDIT:
is returned via
in Django.
Источник:
https://stackoverflow.com/questions/532 ... a-function
1710151839
Гость
Это мой код:
[code]$.ajax({
url: "some_url/",
type: "GET",
dataType: "json",
success: function(data){
console.log(data);
data.forEach(function(element){
console.log(element);
});
}
});
[/code]
I get the error that for each does not work on the [code]data[/code] variable. However, when I log [code]data[/code] to the console, I get
[code][{"model": "app.mdl", "pk": 1, "fields": {"name": "test", "rank": 1}}][/code]
This is clearly an array and iterable, so I don't get what exactly is wrong.
EDIT: [code]data[/code] is returned via [code]JsonResponse[/code] in Django.
Источник: [url]https://stackoverflow.com/questions/53275405/typeerror-data-foreach-is-not-a-function[/url]