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()}); //$('#cl开发者_开发百科ientscontainer').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?
You could produce a jquery object with a DOM for the data being passed back in the callback
$(html)
Then target the two inputs outside the main container and use .replaceWith() to replace the entire element
$("div#").replaceWith($(html).find("div#"));
$("clientID").replaceWith($(html).find("clientID"));
This is just a suggestion, but
$('div#' + clientID').html(html);
might cause some problems.
Try replacing it with
$('div#' + clientID').each(function(){
$(this).html(variableOrArrayElement)
});
精彩评论