weixin_33749242 2015-07-09 20:15 采纳率: 0%
浏览 7

从PHP循环AJAX响应

I want to loop ajax response

response = [
             ["u.profile"],
             ["r.useractivity"],
             ["i.items_job"],
             ["i.setup"],
             ["search"],
             ["i.items_assortment"]
]

I want data = u.profile; data = r.useractivity; etc

Tried Method :

$.each(response,function(key,value){
    console.log(key+":"+value);
});

Getting error in console

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [["u.profile"],["r.useractivity"],["i.items_job"],["i.setup"],["search"],["i.items_assortment"]]

  • 写回答

1条回答 默认 最新

  • weixin_33709219 2015-07-09 20:33
    关注

    The problem is that your response var is an array of arrays (an object) and the default keys are integers.
    It would be an easier (and better) way if you could change it into an array of strings like this one :

    var response = ["u.profile",
                   "r.useractivity",
                   "i.items_job",
                   "i.setup",
                   "search",
                   "i.items_assortment"];
    

    With this, you can easily loop your response like this :

    for(var info in response)
        console.log(info+':'+response[info]);
    

    Hope this will help !

    评论

报告相同问题?