Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

django restframework jquery post

$('form').submit(function(e) {
    e.preventDefault();
    if ($(this).parents("tr") != 0) {
        parent_id = $(this).parents("tr").attr("id").split("_")[1];
        data_str = $(this).serialize() + "&parent_id=" + parent_id;
    } else {
        data_str = $(this).serialize();
    }
    $(this).parents("tr").attr("id").split("_")[1]
    $.ajax({
        type: 'POST',
        url: '{% url 'comment_create' %}',
        data: data_str,
        success: function(json) {
            alert(json.message);
            if (json.status == 200) {
                var comment = json.comment.trim();
                var user = json.user;
                if (!json.parent) {
                    $(comment).insertBefore('.table tr:first');
                } else {
                    $(comment).insertBefore('#comment_' + json.parent_id + ' #child_comment:first');
                    $(".replies").text("답글" + json.comment_count + "개 모두 보기");
                }
            }

        },
        error: function(response) {
            alert("some error occured. see console for detail");
        }
    });
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #django #restframework #jquery #post
ADD COMMENT
Topic
Name
5+3 =