TypeError: data.forEach is not a function

前端 未结 5 1542
孤街浪徒
孤街浪徒 2021-01-18 06:38

This is my code:

$.ajax({
    url: \"some_url/\",
    type: \"GET\",
    dataType: \"json\",
    success: function(data){
        console.log(data);
                 


        
5条回答
  •  礼貌的吻别
    2021-01-18 07:28

    Just check if the data is JSON string.

    data = "[{"model":"app.mdl","pk":1,"fields":{"name":"test","rank":1}}]"
    

    if yes, the you have to do JSON.parse(data) and do forEach on it.

提交回复
热议问题