-2
div에 일련의 HTML 코드를 추가하려고하지만 작동하지 않습니다. 나는 이미 stackoverflow에 게시 된 다른 솔루션을 시도했지만 여전히 작동하지 않습니다.jquery는 추가하지 않지만 div의 내용을 대체합니다.
var placeholder = $('<div class="view view-first img" style="cursor: pointer; display: inline-block;" title="Upload Car Image">' +
'<input type="hidden" value="" class="photodata photoguid" />' +
'<input type="hidden" value="" class="photoid" />' +
'<img src="" style="height: 200px; width: 250px;" class="thumbnailPreview" />' +
'<div class="mask">' +
'<button type="button" class="info btn btn-primary profilepic" style="display: none;" title="Active display photo"><span class="glyphicon glyphicon-bookmark"></span></button>' +
'<button type="button" class="info btn btn-danger deletephoto" style="margin-left: 5px; display: none;" title="Delete Photo"><span class="glyphicon glyphicon-trash"></span></button>' +
'</div>' +
'</div>');
$.ajax({
url: $("#saveImageGuid").val(),
type: "post",
data: '{ recordID: "' + $(".recordID").val() + '", photoguid: "' + fileGroupInfo.uuid + '"}',
datatype: "json",
contentType: 'application/json',
beforeSend: function() {
$(".uploadcontainer").find("#alertmessage").remove();
},
error: function (data) {
alertmessage.attr("class", "alert alert-danger alert-dismissible");
alertmessage.find("#message").text(data.status);
$(".uploadcontainer").append(alertmessage);
},
success: function (data) {
if (data.statusCode == 500)
{
alertmessage.attr("class", "alert alert-danger alert-dismissible");
}
else
{
alertmessage.attr("class", "alert alert-success alert-dismissible");
var guids = jQuery.parseJSON(data.guids);
var thumbnails;
$.each($(guids), function (key, value) {
var uploadcaregeturl = "@Config.UploadCareGETUrl";
uploadcaregeturl = uploadcaregeturl.replace("{0}", value);
placeholder.find(".thumbnailPreview").attr("src", uploadcaregeturl);
$(".thumbnailcontainer").append(placeholder);
});
}
}
});
컨트롤러에서 목록을 가져 와서 img src 특성 내에 배치 한 다음 div에 추가하십시오. Ajax의 성공 부분에서 루프를 실행 한 후에는 모든 자리 표시자를 추가하지 않고 대신 이전 루프에 추가 된 항목을 대체합니다. 내가 잘못한 아이디어.
시도는 우리가 문제를 시각화하는 데 도움이됩니다. – anothershrubery
500 오류가 발생하면 성공 콜백이 호출되지 않고 대신 오류 콜백이 호출됩니다. – Matijs