Thursday, March 30, 2017

Ajax Call is sending empty request.POST or request.body

Hi i am still not clear when using request.POST or request.body.

Anyway this ajax call is sending emprty request.POST, or empty  request.body:

    <script type="text/javascript">
    $(document).ready(function(){

        $(".captcha_form").submit(function(event){
            var check = $('#id_check').val();
            alert(check);
            $.ajax({
                type: "POST", 
                url: "./captcha",
                contentType: "application/json",
                data:check,
                dataType: "json",
                success: function(data) {
                    alert("passa");
                    alert(data.status);
                   
                  },
                error: function(data) {
                    alert("NOT_OK");
                  }         
            });
       
    });
    });
   
    </script>


<form id ="captcha_form" class="captcha_form" action="./captcha" method="post">{% csrf_token %}
    {{form}}
<input type="submit" id="button" class="button" value="Invio"/>
</form>


class check_box_form(forms.Form):
    scelte = [('Yes','Yes'),('No','No')]
    check = forms.ChoiceField(label='I am a Robot       ',choices=scelte)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c600a8c8-486b-4359-862e-068ca471d5e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment