我试图在几个画布上绘制从 ajax 请求返回的元素,但是它只是将所有图像绘制到第一个画布上。
如何访问成功函数中的每个画布元素来绘制图像?
jQuery
$(document).ready( function() {
$('.citizen').each( function( i, citizen) {
$.ajax({
type : 'GET',
url : 'getCitizenPhoto.htm',
data : {
socialSecurityNumber : $(citizen).val()
},
dataType : 'text',
success : function(data,i) {
var image = new Image();
image.src = data;
image.onload = function() {
var ctx = document
.getElementById("#photoCvs")
.getContext('2d');
ctx.drawImage( image, 0, 0, 200, 200 );
}
}
});
});
HTML
<p>Victims</p>
<c:forEach items="${victimMonitoringList}" var="victims">
<div id="victim_row">
<input class="citizen" id= "socialSecurityNumber" value= "${vitims.socialSecurityNumber}"/>
<canvas id="photoCvs" class="canvas" height="200" width="200"></canvas>
</div>
<div id="criminals">
<c:forEach items="${criminalMonitoringList}" var="criminals">
<div id="criminal_row">
<p>Criminals</p>
<input class="citizen" id= "socialSecurityNumber" value= "${criminal.socialSecurityNumber}"/>
<canvas id="photoCvs" class="canvas" height="200" width="200"></canvas>
</div>