2011-10-18 111 views
2

我有頁面,它會顯示我們的產品,所以它會加載一些圖像和數據,如果我一次加載它,它會很大,所以我決定去做它通過Ajax和的jQuery做到這一點,這裏是我的代碼:無法顯示已添加的元素

var static = 1; 
$('.carousel-next').live('click',function(){ 
$(this).attr("disabled", false); 
var pos_eq = static++; 
var url = 'ajax/ajax.php?count=' + pos_eq; 
if ($('.myList').children('li').length <= pos_eq) 
{ 
$.getJSON(url,function(data){ 
    if (data[0] != 404) 
    { 
$('.myList').append(data[0]); 
$('.myList').children('li').eq(pos_eq).children(".stagger").css({"left":"1200px"}); 
$('.myList').children('li').eq(pos_eq).children(".imac").css({"left":"1200px"}); 
$('.myList').children('li').eq(pos_eq).children(".stagger").animate({"left":"65px","effect":"slide"},500); 
$('.myList').children('li').eq(pos_eq).children(".imac").animate({"left":"350px","effect":"slide"},700); 
    } 
}); 
} 
else 
{ 
$('.myList').children('li').eq(pos_eq).children(".stagger").css({"left":"1200px"}); 
$('.myList').children('li').eq(pos_eq).children(".imac").css({"left":"1200px"}); 
$('.myList').children('li').eq(pos_eq).children(".stagger").animate({"left":"65px","effect":"slide"},500); 
$('.myList').children('li').eq(pos_eq).children(".imac").animate({"left":"350px","effect":"slide"},700); 
} 
}); 

$('.carousel-previous').live('click',function(){ 
$(this).attr("disabled", false); 
var pos_eq2 = static--; 
if (pos_eq2 < 0) 
pos_eq2 = 0; 
$('.myList').children('li').eq(pos_eq2).children(".stagger").css({"left":"-1200px"}); 
$('.myList').children('li').eq(pos_eq2).children(".imac").css({"left":"-1200px"});  $('.myList').children('li').eq(pos_eq2).children(".stagger").animate({"left":"65px","effect":"slide"},500); $('.myList').children('li').eq(pos_eq2).children(".imac").animate({"left":"350px","effect":"slide"},700); 
}); 

當我使用它,它會從ajax.php頁面獲得數據並將其添加到頁面(我看到了一個源代碼,這樣做後)但它現在將顯示它們,下面的部分應顯示添加到頁面後的元素,但它不能。

$('.myList').children('li').eq(pos_eq).children(".stagger").css({"left":"1200px"}); 
$('.myList').children('li').eq(pos_eq).children(".imac").css({"left":"1200px"}); 
$('.myList').children('li').eq(pos_eq).children(".stagger").animate({"left":"65px","effect":"slide"},500); 
$('.myList').children('li').eq(pos_eq).children(".imac").animate({"left":"350px","effect":"slide"},700); 

問題在哪裏?

+0

做一個'console.log(data [0])'並且首先確保你得到所需的輸出。 –

+0

我使用警報(數據[0])進行檢查,它會得到數據。 –

回答

0

Append()需要一個Dom元素,一個HTML字符串或一個Jquery對象來工作。 所以也許問題出在你的數據上。你能告訴我們從console.log(data)得到什麼輸出嗎?