Ajax problem after deleting a div, then creating a new one

Posted by Matt Nathanson on Stack Overflow See other posts from Stack Overflow or by Matt Nathanson
Published on 2010-04-13T20:36:11Z Indexed on 2010/04/13 20:42 UTC
Read the original article Hit count: 271

Filed under:
|

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!!!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX