我有一个 ajax 调用,它从 Coldfusion CFC 方法请求数据并在 div 中显示数据。还有一个删除此数据的链接,该链接使用相同的 CFC 但删除方法不同。两种方法都可以独立工作。我似乎无法弄清楚如何将调用封装在一个函数中,并在删除成功后刷新 div。这是代码:
ajax 调用
var caseid = <cfoutput>'#URL.ID#'</cfoutput>;
var siteurl = <cfoutput>'#APPLICATION.url#'</cfoutput>;
var html = "";
function assetsPost() {
$.ajax({
cache: false,
type:'GET',
url:'cfc/cfc_Asset.cfc?method=qAsset&returnformat=json',
dataType: "json",
data: {
assetgrp_id: caseid,
},
success:function(data) {
if(data) { // DO SOMETHING
jQuery.each(data, function(i, val) {
$('#picoutputannotation').html(data[i].annotation);
var asset_id = data[i].value;
var img = siteurl + 'assets/images/thumbs_check2/' + data[i].thumb;
var removeimg = siteurl + 'assets/images/remove.png';
var annotation = data[i].annotation;
html += "<div class='block-pics'>";
html += "<img src='" + img + "'>";
html += "<div class='note'>";
html += annotation;
html += "</div>";
html += "<div class='block-pics-remove'>";
html += "<a class='delete-asset' id='" + asset_id + "'><img src='" + removeimg + "'></a>";
html += "</div>";
html += "<div class='bot'></div>";
html += "</div>";
});
$('#picoutput').html( html );
} else { // DO SOMETHING
}
}
});
}
assetsPost();
这是删除脚本:
$(document).on("click", ".delete-asset", function() {
var del_id = $(this).attr('id');
$.ajax({
type:'GET',
url:'cfc/cfc_Asset.cfc?method=DeleteAsset&returnformat=json',
dataType: "json",
data: {
delete_id: del_id,
},
success:function(data) {
if(data) { // DO SOMETHING
$('#picoutput').empty();
{assetsPost()};
$('#picoutput').fadeIn('fast');
} else { // DO SOMETHING
}
}
});
});
这是html:
<div class="grid_6">
<div id="picoutput"></div>
</div>
</div>