Problem with selector context
I'm currently implementing a simple chat for my website and have a problem.
I want to update the chat messages and the currently active users with ajax. I know how to do it with 2 ajax calls but I want to do it in one.
I have a file which returns the entries and users like this:
- <div id="entries">These are the entries</div>
- <div id="users">These are the users</div>
My jQuery ajax request looks like this:
- $.ajax({
- type: "GET",
- url: "chat.php",
- success: function(retHtml) {
- var entriesHtml = $("#entries", retHtml).html();
- var usersHtml = $("#userlist", retHtml).html();
- $("#chat").html(entriesHtml);
- $("#userlist").html(usersHtml);
- }
- });
The variable retHtml contains the HTML I want, but 'entriesHtml' and 'usersHtml' are null.
I already tried wrapping retHtml in $() but that doesn't work either.
Can anyone tell me why that is? Or is there a better way to do this?
Thanks!
Thomas