我正在构建一个自定义CMS,您可以使用ajax和jquery 1.4.2添加和删除客户端 .
我的问题出在我删除div之后 . ajax用于完成此操作并自动刷新..但是当我去创建一个新的div(没有硬刷新)时,它将它放回我刚刚删除的div的插槽中 .
我怎样才能完全忘记我刚刚删除的div并将新div放在下一个数据库表中?
//Add New client //
function AddNewClient() {
dataToLoad = 'addClient=yes';
$.ajax({
type: 'post',
url: '/clients/controller.php',
datatype: 'html',
data: dataToLoad,
target: ('#clientssidebar'),
async: false,
success: function(html){
$(this).click(function() {reInitialize()});
//$('#clientssidebar').html(html);
$('div#' + clientID).slideDown(800);
$(this).click(function() { ExpandSidebar()});},
error: function() {
alert('An error occured! 222');}
});};
//Delete Client //
function DeleteClient(){
var yes = confirm("Whoa there chief! Do you really want to DELETE this client?");
if (yes == 1) {
dataToLoad = 'clientID=' + clientID + '&deleteClient=yes',
$.ajax({
type: 'post',
url: '/clients/controller.php',
datatype: 'html',
data: dataToLoad,
success: function(html) {
alert('Client' + clientID + ' should have been deleted from the database.');
$(this).click(function() {reInitialize()});
$('div#' +clientID).slideUp(800);
},
error: function() {
alert('error');
}});};};
//Re Initialize //
function reInitialize() {
$('#addnew').click(function() {AddNewClient()});
$('.deletebutton').click(function() {clientID = $(this).parent().attr('id'); DeleteClient()})
$('.clientblock').click(function() {clientID = $(this).attr('id'); ExpandSidebar()});};
//Document Ready //
$(document).ready(function(){
if ($('isCMS')){
editCMS = 1;
$('.deletebutton').click(function() {clientID = $(this).parent().attr('id'); DeleteClient()});
$('#addnew').click(function() {AddNewClient()});
$('.clientblock').click(function() {clientID = $(this).attr('id'); ExpandSidebar()});
$('.clientblock').click(function() {if (clickClient ==true) {
$(this).css('background-image', 'url(/images/highlightclient.png)');
$(this).css('margin-left' , '30px'); };
$(this).click(function(){
$(this).css('background-image', '');
});
$('.uploadbutton').click(function(){UploadThings()});
});
}
else ($('#clientscontainer'))
{
$('#editbutton').css('display', 'none');
};
});
请帮忙!!!
1 回答
您是否可以使用
.remove
jQuery函数而不是将display
属性设置为none
?