TypeError: data.forEach is not a function

前端 未结 5 1575
孤街浪徒
孤街浪徒 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:17

    just check for either it is string or JSOn array

    if(typeof(data) === "string"){data = JSON.parse(data)}
     data.forEach(function(element){
                console.log(element);
            });
    

提交回复
热议问题