Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {%extends 'base_template.html'%}
- {%block title%}
- <title> Simple Ajax Demo </title>
- {%endblock%}
- {%block javascript%}
- <script>
- $(document).ready(function(){
- $("#formi").submit(function(event){
- $.ajax({
- type:"POST",
- url:"{% url 'haha:ajax' %}",
- data: {
- username : $('#username').val(),
- password : $('#password').val(),
- csrfmiddlewaretoken: {% csrf_token %},
- },
- success: function(data){
- alert('asdas');
- },
- });
- });
- });
- </script>
- {%endblock%}
- {%block content%}
- <div>
- <form method="post" id="formi">
- {%csrf_token%}
- Username:<input type="text" name="username"><br>
- Password:<input type="text" name="password"><br>
- <button type="submit">CLick Me</button>
- </form>
- </div>
- {%endblock%}
- def ajax(request):
- if request.method == 'POST':
- username = request.POST['username']
- password = request.POST['password']
- Users.objects.create(username=username, password=password)
- return render(request,'core/ajax.html')
- username = request.POST.get('username')
- password = request.POST.get('password')
Add Comment
Please, Sign In to add comment