Send data with POST-request wont work in Django with AJAX

Hi there,

I work on a project in Django and want to use ajax for one task:

I want to pass data, after it was processed by ajax, from my template file to my file (with a POST request), to again make it visible in my templates file.

Templates-file → Proccessed data → POST-request → → Template-file

But it just wont work for me.

Did I make a mistake?

My HTML-Templates-File:

<script type="text/javascript">

    var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();

    function csrfSafeMethod(method) {
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));

        beforeSend: function (xhr, settings) {
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);

        url: "/save",
        data: {
            'value': inputDataArray  //I have already defined "inputDataArray" before
        success: function (res, status) {
        error: function (res) {

My file:

def save(request):
    if request.method == 'POST':
        request_getdata = request.POST.get("value", None) 
    return render(request, "response.html", {"data":request_getdata})     

And my urls-py file:

urlpatterns = [
    path('', views.index , name='index'),
    path('save', , name='save'),]

So I try display it at " response.html " with…


…but it just will reload the current page and does not pass any data to the response.html-file.

Does anyone knows what my error is here?

Thanks so much in advance

You’re not submitting HTML form data in your POST, you’re sending a JSON object.

See the docs on request.POST for how to retrieve that data.