Understanding jQuery.get()
Hello. I am pretty new to jQuery and AJAX in general, and I am trying to figure out how exactly the jQuery.get() function works. I am writing a web application that pulls some html data from a php script, updates a div with that data, and updates that div's scrollbar (using the tinyscrollbar plugin) to "fit" the new contents.
Here is my code:
- $(".menu").click(function(){
- var oldContent = $("#dyn").html();
- $.get("populate.php", {name: cleanMeUp($(this).html())}, function(data, statusMsg){ //gets page from server based on what menu item was clicked
- if (data != "blank") {
- $("#dyn").html("<h3>Loading...</h3>");
- $("#dyn").html(data);
- } else $("#dyn").html(oldContent);
- scrollbar.update();
- },
- "html");
- });
I have highlighted the line of code that does not do what I expect. I would expect this code to load the div with new contents and call scrollbar.update() when it receives the data from the server and updates the DOM. However, when I view the site in Chrome or IE8, the scrollbar does not usually update. Is there a way to run the scrollbar.update() function only AFTER the DOM has been updated with data from the server?
Like i said, I am a newbie and not ashamed to admit it. I would
really appreciate some help. Thank you so much.