Das ist mein Template-Fragment für Kommentare/Wie URL an Ajax Erfolg übergeben?
{% for comment in comments %}
<div class="comment-wrapper">
<a href="{% url 'comment:update_comment' slug=product.slug id=comment.id %}" class="comment-edit-img">
<img src="{% static 'media/work_images/icons-edit.png' %}" alt="">
</a>
<a href="{% url 'comment:delete_comment' comment.pk %}" class="comment-del-img">
<img src="{% static 'media/work_images/icons-delete.png' %}" alt="">
</a>
<p class="comment-text">{{comment.comment_text}}</p>
{% if comment.update_date != comment.posted_date %}
<span class="comment-author">
{% trans 'Posted' %}:
{{comment.author}}
</span>
<span class="comment-date">
{% blocktrans trimmed with update=comment.update_date %}
{{update}}
{% endblocktrans %}
</span>
{% else %}
<span class="comment-author">
{% trans 'Updated by' %}:
{{comment.author}}
</span>
<span class="comment-date">
{% blocktrans trimmed with posted=comment.posted_date %}
{{posted}}
{% endblocktrans %}
</span>
{% endif %}
</div>
{% endfor %}enter code here
Mein Ajax-Code/
$('#add-comment').click(function (e) {
e.preventDefault();
var form = $('#add-comment-form');
$.post(form.attr('action'), form.serialize()).done(function(data) {
$('#comment-box').prepend(
"<div class='comment-wrapper'>"+
"<a href='???' class='comment-edit-img'>up</a>"+
"<a href='???' class='comment-del-img'>x</a>"+
"<p class='comment-text'>"+data.text+"</p>"+
"<span class='comment-author'>"+data.author+"</span>"+
"<span class='comment-date'>"+data.date+"</span>"+
"</div>"
);
})
});
Wie kann ich die URL der Adresse für Tag <a>
die gleichen wie in der Vorlage übergeben? Oder gibt es eine bessere Lösung für Ajax?
Bitte versuchen Sie, Titel nützlich und prägnant zu halten, und frei von gesprächigen bitte-Half-Me-Material so viel wie möglich. Es kann sich lohnen, die Titelseite zu durchsuchen, um zu sehen, wie Titel allgemein geschrieben werden. – halfer