Get POST data in django form AJAX from

前端 未结 5 556
甜味超标
甜味超标 2021-01-15 19:28

I\'m going to get parameter form AJAX request in Django, Here\'s what I\'m doing:

base.html:

{% csrf_tok
5条回答
  •  一向
    一向 (楼主)
    2021-01-15 20:01

    Prevent the form from submitting with "e.preventDefault()". Also, it's probably better to bind to the form just in-case the user hits Enter instead of clicking:

    base.html

    {% csrf_token %}
    First name: 
    
    
    

    main.js

    $(document).ready(function(){
        $("#register").live("submit", function(e){
            $.post("/", {
                name: "MY TEXT",
            });
            e.preventDefault();
        });
    });
    

提交回复
热议问题