2010-04-13 2 views
1

Je crée un CMS personnalisé où vous pouvez ajouter et supprimer des clients en utilisant ajax et jquery 1.4.2.Problème Ajax après la suppression d'un div, puis la création d'un nouveau

Mon problème se situe après avoir supprimé un div. L'ajax est utilisé pour compléter ceci et se rafraîchir automatiquement. Mais quand je vais créer un nouveau div (sans un rafraîchissement) il le remet dans la fente du div que je viens de supprimer.

Comment puis-je faire en sorte d'oublier complètement la div que je viens de supprimer et de placer la nouvelle div dans la table de base de données suivante?

 

//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'); 
     }; 

     }); 

Aidez-nous!

Répondre

0

Pourriez-vous utiliser la fonction jQuery .remove au lieu de définir sa propriété display sur none?

+0

lorsque je change slideUp pour supprimer je perds ma fonctionnalité ajax de rechargement avec le nouveau div –

Questions connexes