2013-08-19 48 views
0

我有此腳本:加載圖像隨着AJAX(jQuery的)

$.ajax({ 
    type: "GET", 
    url: '/get.php?id=' + c + '&type=1', 
    dataType: "html" 
}).done(function (a) { 
    $(".playerr:eq(" + b + ")").html(a).show() 
}); 

我怎樣才能添加加載圖像?

+0

我的整個功能是這樣的:var PML = -1;函數showpl(b,c,d){if(pml!= -1)$(「。playerr:eq(」+ pml +「)」)。html('')。hide(); var b = $(「。」+ d).index(b); $ .ajax({type:「GET」, url:'/get.php?id='+ c +'&type = 1', dataType:「html」 })。done(function(a) {(「。playerr:eq(」+ b +「)」)。html(a).show() }); pml = b; 返回false } –

回答

1

您可以使用beforeSendsuccess或進行顯示和隱藏加載圖像

$.ajax({ 
    type: "GET", 
    url: '/get.php?id=' + c + '&type=1', 
    dataType: "html" 
}).done(function (a) { 
    $(".playerr:eq(" + b + ")").html(a).show(); 
    $("#img1").hide(); 
}).beforeSend(function(){ 
     $("#img1").show(); 
}); 
+1

您可以將圖像隱藏在.done()上,因此即使出現錯誤,圖像也會被隱藏,否則它會一直顯示。 – Farhan

+0

是的,我們也可以把它藏起來。 – Adil

+0

我添加了我的整個功能,我作出了改變,你說如何,但不工作.. –