2011-03-12 53 views
3

追加列表项我打电话使用AJAX的附加返回的HTML usign下面阿贾克斯:顶部

$.ajax({ 
    type: "POST", 
    url: "proc/process.php", 
    data: dataString, 
    cache: false, 
    success: function(html){ 
     $("ul#lists").append(html); 
     $("ul#lists li:last").fadeIn("slow"); 
     $("#flash").hide(); 
    } 
}); 

代码它在UL#结束追加<li></li>项目一个PHP处理文件名单。我希望返回的列表项<li></li>位于列表的顶部,而不是最后添加。我怎么做??

回答

5

您可以尝试.prepend()功能:

$("ul#lists").prepend(html); 
$("ul#lists li:first").fadeIn("slow"); 

而且这里有一个live demo

+0

感谢它为我的作品也 – Peeyush 2011-10-09 11:37:46

1

这里是你想要的东西:

$.ajax({ 
type: "POST", 
url: "proc/process.php", 
data: dataString, 
cache: false, 
success: function(retHtml){ 
    var oldhtml = $("ul#lists").html(); 
    $("ul#lists").html(retHtml + oldhtml); 
    $("ul#lists li:first").fadeIn("slow"); 
    $("#flash").hide(); 
} 
});