question regarding json responses and datatables

question regarding json responses and datatables

BartTechneBartTechne Posts: 24Questions: 6Answers: 0
edited April 2021 in Free community support

Javascript:

$('#submit_phones').click( function() {
            var data = table.rows( { selected: true } ).data().toArray();
            alert(data)
            var URL = "{% url 'upload_devices' %}";
            $.ajax({
                type: "POST",
                url: URL,
                dataType: 'JSON',
                data: {
                    info : data,
                    csrfmiddlewaretoken : '{{ csrf_token }}',
                },
                success : function(data) {
                    alert("Successfully sent the data to Django");
                },
                error : function(xhr,errmsg,err) {
                    alert("Could not send URL to Django. Error: " + xhr.status + ": " + xhr.responseText);
                }
            });
        });

when i get a reply i dontget the table names. and the "info" dictionary contains [1][0] with intel of row 1 and info [2][0]

how to remove those second indexes ?

    {
       "info[0][]":[
          information
       ],
       "info[1][]":[
         information
       ],
       "csrfmiddlewaretoken":[
          "G6al1GeiznUPaWkrJ8RE4wfghqzaDziOkv3J8g03NP1DzHmS6iGyy1G1XlmYWUYT"
       ]
    }

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    It looks like a string, so you would need to reform that response to be the expected format, either on the client or the server.

    Colin

This discussion has been closed.