1

I intend to send a comment form by JQuery,

The html form

<div>
    <h4>Comments</h4>
    <form method="POST" id="createComment"> {% csrf_token %}
    <textarea class="form-control" id="commentContent" rows="5" name='comment'></textarea>
    <br>
    <button type="submit" id="commentBtn" class="btn btn-primary">Post Your Comment</button>
    </form>
</div>

The js

<script type="text/javascript" src="/static/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.csrf.js"></script>

<script type="text/javascript">
$(document).ready(function(){
    var article_id = {{ article.id }};
    var page_number = {{ page.number }};

    $("#commentBtn").click(function(){
        var comment =$("#commentContent").val();
        var param = {"article_id":article_id, "content":comment};

        $.post("/article/comment/create/", param, function(data){
            var ret = JSON.parse(data);
            if (ret["status"]=="ok") {
                $("#commentContent").val("");
                window.location.href="/article/detail/{{ article.id }}?page_number={{ page.num_pages }}" \\change to the final page
            }else{
                alert(ret["msg"]);
            }
        });
    })
});
</script>

However, I got page not working error when Press the submit button:

This page isn’t working    
If the problem continues, contact the site owner.    
HTTP ERROR 405    

I double checked the import js but found no problem.

How could I solve such an error?

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138

1 Answers1

1

Try add return false; at end of the function then it should work.

some related post you can see here

Ramesh
  • 76
  • 1
  • 9