Javascript jquery没有';t追加但替换div的内容
我试图将一组html代码附加到div中,但不起作用。我已经尝试过stackoverflow中发布的其他解决方案,但仍然不起作用Javascript jquery没有';t追加但替换div的内容,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,我试图将一组html代码附加到div中,但不起作用。我已经尝试过stackoverflow中发布的其他解决方案,但仍然不起作用 var placeholder = $('<div class="view view-first img" style="cursor: pointer; display: inline-block;" title="Upload Car Image">' + '<input type="hidd
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);
});
}
}
});
var占位符=$(“”+
'' +
'' +
'' +
'' +
'' +
'' +
'' +
'');
$.ajax({
url:$(“#saveImageGuid”).val(),
类型:“post”,
数据:“{recordID:”+$(“.recordID”).val()+”,photoguid:“+fileGroupInfo.uuid+”}”,
数据类型:“json”,
contentType:'应用程序/json',
beforeSend:函数(){
$(“.uploadcontainer”).find(“#alertmessage”).remove();
},
错误:函数(数据){
alertmessage.attr(“类”,“警报-危险警报-可解除”);
alertmessage.find(“#message”).text(data.status);
$(“.uploadcontainer”).append(alertmessage);
},
成功:功能(数据){
如果(data.statusCode==500)
{
alertmessage.attr(“类”,“警报-危险警报-可解除”);
}
其他的
{
attr(“类”,“警报成功警报可驳回”);
var guids=jQuery.parseJSON(data.guids);
var缩略图;
$。每个($(GUID)、函数(键、值){
var uploadcaregeturl=“@Config.uploadcaregeturl”;
uploadcaregeturl=uploadcaregeturl.replace(“{0}”,值);
占位符.find(“.thumbnailPreview”).attr(“src”,uploadcaregeturl);
$(“.thumbnailcontainer”).append(占位符);
});
}
}
});
我从controller获取一个列表,然后将其放入img src属性中,然后将其附加到div。在ajax的成功部分执行循环后,它不会附加每个占位符,而是替换上一个循环中附加的占位符。知道我哪里出错了吗。现在开始工作了。我将占位符放在成功部分中,并在控制器中重新构造代码,以便更好地处理状态代码
$.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) {
alertmessage.attr("class", "alert alert-success alert-dismissible");
var guids = jQuery.parseJSON(data.guids);
var thumbnails;
$.each($(guids), function (key, value) {
var placeholder = $('<div class="view view-first img...');
var uploadcaregeturl = "@Config.UploadCareGETUrl";
uploadcaregeturl = uploadcaregeturl.replace("{0}", value);
placeholder.find(".thumbnailPreview").attr("src", uploadcaregeturl);
$(".thumbnailcontainer").append(placeholder);
});
}
});
$.ajax({
url:$(“#saveImageGuid”).val(),
类型:“post”,
数据:“{recordID:”+$(“.recordID”).val()+”,photoguid:“+fileGroupInfo.uuid+”}”,
数据类型:“json”,
contentType:'应用程序/json',
beforeSend:函数(){
$(“.uploadcontainer”).find(“#alertmessage”).remove();
},
错误:函数(数据){
alertmessage.attr(“类”,“警报-危险警报-可解除”);
alertmessage.find(“#message”).text(data.status);
$(“.uploadcontainer”).append(alertmessage);
},
成功:功能(数据){
attr(“类”,“警报成功警报可驳回”);
var guids=jQuery.parseJSON(data.guids);
var缩略图;
$。每个($(GUID)、函数(键、值){
var placeholder=$('尝试创建一个帮助我们可视化您的问题。当您收到500个错误时,将不会调用您的成功回调,而是调用您的错误回调。