循環有效。但標題的更新沒有。被註釋掉的警報確實表明數據是正確的。jQuery .each()AJAX
<script>
var usercount = 0;
var nbw = '';
var _$this = '';
$('.alphabet').each(function() {
_$this = $(this);
nbw = $(this).val();
$.ajax({
type: "Get",
url: "cfc/basic.cfc?method=CountUsersByLetter&returnformat=json",
data: "nbw=" + nbw,
datatype: "html",
success: function (response) {
usercount = parseInt(response.substring(0, 10));
//$(_$this.target).attr('title', usercount);
},
error: function (xhr, textStatus, errorThrown) {
alert('errorThrown');
}
});
$(_$this.target).attr('title', usercount);
//alert(nbw + ' usercount=' + usercount);
});
</script>
你射擊(大概)一次26 HTTP請求?這聽起來不是一個好主意。 – 2012-02-04 21:02:29
'$(_ $ this.target)'是錯誤的。 '_ $ this'是'$(this)',$(this)沒有'target'。只有'event.target'。不過我認爲你也應該改變它:'_ $ this.attr('title',usercount);' – noob 2012-02-04 21:07:43
我可以用字母計數返回查詢。我只是不善於處理JSON回報。 – user990016 2012-02-04 21:12:24