ajax - Passing div element to success callback jquery -
i using lis obtain list of <li>
dom, , in each li , update projectphoto after ajax call. "li" in callback function referring last item in lis
, there way overcome this, or such pass value ?
p/s: pretty sure has been discussed before can't reach right terminology. apology in advance.
var lis = $('.porject_list li'); (var = 0; < lis.length; i++) { var li = lis.eq(i); var projectid = li.attr('data-project-id'); $.get("/webapi/projects/projectphoto/" + projectid, function (res) { $("img", li).attr('src', res); }); }
you may try (just wrap ajax
call in function)
(function(current){ $.get("/webapi/projects/projectphoto/" + projectid, function (res) { $("img", current).attr('src', res); }); })(li);
update :
i didn't notice var li = lis.eq(pos);
, this, anyways, can use
var li = lis[i];
to current li
in loop.
Comments
Post a Comment