Ajax problem after deleting a div, then creating a new one
- by Matt Nathanson
I'm building a custom CMS where you can add and delete clients using ajax and jquery 1.4.2.
My problem lies after I delete a div. The ajax is used to complete this and refresh automatically.. But when I go to create a new div (without a hard refresh) it puts it back in the slot of the div I just deleted.
How can I get this to completely forget about the div i just deleted and place the new div in the next database table?
link for reference: http://staging.sneakattackmedia.com/cms/
//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');
};
});
Please help!!!