Why is my content being overwritten instead of replaced in jQuery/Ajax?

Posted by Matt Nathanson on Stack Overflow See other posts from Stack Overflow or by Matt Nathanson
Published on 2010-04-16T17:50:28Z Indexed on 2010/04/16 17:53 UTC
Read the original article Hit count: 192

Filed under:
|

I've got jquery being used in ajax to pass some contents into a database, my problem however has nothing to do with the db..

I have input fields in an id called

#clientscontainer
. When I click "save" in that container, it automatically refreshes the container correctly ...
 $('#clientscontainer').html(html);

The problem is, a couple of those input fields (such as a description and title), have instances in another div that i want to refresh upon the save click. The other ID is:

 $('div#' + clientID')

When I do

$('div#' + clientID').html(html); 
it refreshes the content from clientscontainer in it instead of just the variables that I want to update.

When I try to pass just the variable

$(blurb).html(html); 
it updates the blurb but it ONLY displays that variable in the div# clientID div... whereas I just want to replace it.

Here is the AJAX portion of the function

...//variables//
    dataToLoad = 'clientID=' + clientID + '&changeClient=yes' + '&project=' + 
descriptionSubTitle +   '&campaign=' + descriptionTitle + '&label=' +
 descriptionLabel + '&descriptionedit=' + description +     '&blurbedit=' + blurb;

    $.ajax({
    type: 'post',
    url: ('/clients/controller.php'),
    datatype: 'html',
    data: dataToLoad,
    success: function(html){        
        dataToLoad = 'clientID=' + clientID + '&loadclient=yes&isCMS=' + editCMS;   
    $.ajax({
    type: 'post',
    url: '/clients/controller.php',
    datatype: 'html',
    data: dataToLoad,
    async: false,
    success: function(html){

        //$('#clientscontainer').focus(function() {reInitialize()});
        //$('#clientscontainer').ajaxComplete(function(){reInitialize()});

        $('#clientscontainer').html(html);
        $('div#' + clientID).each(function(){

        $('#editbutton').click(function() {EditEverything()});


        }
            ,
    error: function() {
    alert('An error occured! 222');
    }
    });},
        error: function() {
        alert('An error occured! 394');
                          }
    });

any suggestions?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX