0

I am posting a comment to a thread with an AJAX call.

It sends the request to the server as it should. How can I append the new comment to the other comments?

I guess it will be something like

.done(function () {
    ...().after(html);
});

The style of the comments is a bit complicated so it's not enough to just append some text to a div. How is this normally done?

I am using jQuery and Django. Should the html be generated by server-side with Django templates or just client-side with jquery (maybe a jquery templating system)?

How is this done at sites as Facebook? Is it by appending html when posted successfully or is the page refreshing with an interval and updating the entire page?

Jamgreen
  • 10,329
  • 29
  • 113
  • 224
  • page refresh is not common any more. Can return json and use client side logic to parse into the DOM or return html....choice is yours – charlietfl Nov 05 '14 at 23:09

4 Answers4

0

You have two ways: - your web server return a JS code who add the HTML to your view, it may be more simple to code, because you can use python code. - your web server just return the data and you have to manually create the HTML, i'm not fan of this because you have to recreate the HTML and you will have to maintain 2 codes if the HTML code of your comments change.

I would advise you to generate the HTML server-side.

0

you could add a div with a class than fill this div with your new comment. something like

$('.div_comment').last().append('<div class="comment">' + newComment + '</div>');
Robouste
  • 3,020
  • 4
  • 33
  • 55
0

If you are having trouble with your .css after loading the new comment to your webpage, take a look at this link, it helped me a lot: Updating components/css and for the loading of the content I would just recommend $("#component").append(html) Though I have to say, be careful when setting directly into HTML, because you might have troubles with functionalities, like on click etc. Take a look at backbone.js for dynamically adding content

Community
  • 1
  • 1
Fabio
  • 103
  • 10
0

simply just use .append , click link to see for yourself

Fas M
  • 429
  • 2
  • 11