如何循环$.post
回调函数?
这是我想循环的代码......
$.post("p.php",{config: config1, test: test1}, function(data)
{
});
答案 0 :(得分:1)
您可以使用$.each
方法循环遍历一个或多个对象。以下是使用$.each
方法进行数组和对象循环的示例。
循环数组
$.each([52, 97], function(index, value) {
alert(index + ': ' + value);
});
循环对象
var map = {
'flammable': 'inflammable',
'duh': 'no duh'
};
$.each(map, function(key, value) {
alert(key + ': ' + value);
});
正如您在评论中提到的,response
包含4个p
标记,您需要将它们附加到页面上的li
标记中,您可以尝试使用此标记。
$.post("p.php",
{ config: config1, test: test1},
function(data){
//if you have an to li then use id selector or
//if you have a class to li then use class selector
$('liSelector').append(data);
});
答案 1 :(得分:0)
$.each(data, function(k,v) {
...
});