Why is my content being overwritten instead of replaced in jQuery/Ajax?
- by Matt Nathanson
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?