T
T
Tash1moto2016-03-05 15:12:11
JavaScript
Tash1moto, 2016-03-05 15:12:11

Where can I find an example of submitting an axaj post in django (not a form)?

Hello.
Help me find the simplest example of sending data via ajax, post method for further processing in the view,
(I'm not sending a form), but data from custom attributes in tags.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2016-03-05
@Tash1moto

simpleAjax.js

var xhr = new XMLHttpRequest();
xhr.open("POST", '/some-url', true)
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send("param_name=param_val");

views.py
def simple_ajax(request):
    if request.method == 'POST':
        print(request.POST.get('param_name'))

S
sim3x, 2016-03-05
@sim3x

Work like with a form - so as not to suffer with manual validation
https://docs.djangoproject.com/en/1.9/ref/request-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question