[Answer]-Check that the username already exists in AJAX

1👍

You should include CSRF token in your request (or decorate your register method with csrf_exempt – what I don’t recommend).

Just take a look to this example
https://docs.djangoproject.com/en/dev/ref/csrf/#ajax


As Daniel Roseman has mentioned in comments, you should use GET method for your purposes. It’s correct from semantic view-point of HTTP methods.
Read more Here

0👍

this should work

  $.ajax({
     csrfmiddlewaretoken: document.getElementsByName('csrfmiddlewaretoken')[0].value,

                        url: '',
                        data: 'username='+value,
                        type: 'POST',
                        success: function(data){
                            console.log(data);
                        }
                    });
👤ivan

Leave a comment