TypeError: data.forEach is not a function

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

    Change your success function to this, the JSON.parse() function is required to iterate over the JSON string:

    success: function(data){
            data = JSON.parse(data);
            console.log(data);
            data.forEach(function(element){
                console.log(element);
            });
    

提交回复
热议问题