N
N
Nadia2021-01-30 01:44:01
Django
Nadia, 2021-01-30 01:44:01

How to convert received response from ajax to python array?

Hello, please tell me

there is a button, when pressed, ajax should work, send a request to the server and receive a response in the form

{
   "ok":true,
   "result":[
      {
         "update_id":377151451,
            "chat":{
               "id":-371111,
            },
            "date":1611956075,
         }
      },
      {
         "update_id":3771522,
            "chat":{
               "id":-379333
            },
            "date":1611956084,
            ]
         }
      }
   ]
}


Here is my button handler
$("#update_groups").click(function () {
            $.ajax({
                type: 'POST',
                url: 'https://api.telegram.org/bot.../getUpdates',
                dataType: 'json',
                success: function (data) {
                    {#alert(data.result);#}
                    $.ajax({
                        type: 'POST',
                        url: 'http://127.0.0.1:8000/main/',
                        dataType: 'JSON',
                        data: data
                    });
                }
            });
        })


action
if request.method == 'POST' and request.is_ajax():
        form = request.POST


And in the end, this is what is stored in the form variable.
60148f329fe12964226613.png

Please tell me how to make it so that I can get the result as an array, and not as separate lines? thanks in advance)))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nadia, 2021-02-01
@NadiiaN

who needs this solution:

$.ajax({
                            type: 'POST',
                            url: '{% url 'send_message' %}',
                            datatype: "JSON",
                            data: JSON.stringify(data)

action
req = request.POST
update_groups = json.loads(req)

D
Dima Pautov, 2021-01-30
@bootd

Can you google how to convert data to json in python?
https://www.google.com/search?q=python+json&oq=pyt...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question