POST unanswered in Django / Javascript

I have a happy javascript based client that talks to my Django server code. I use several XMLHttpRequests for interaction, and everything is all right. Now there is one user interaction in which I would like to receive information about the user on the server, but I do not need / do not need an answer.

As I understand it, Django all views MUST respond with an HttpResponse element. I can send back an empty or HttpResponseNotModified response. But all I get seems to be causing the browser side to switch to a blank screen.

I do not want to change pages, reload or anything else. Just leave your browser session alone. I do not need confirmation and do not mind if some of the POST messages are even lost among a large number of responses.

I CAN execute XMLHttpResponse and catch the response and ignore it. But I wonder if there is anything like that.

0
source share
1 answer

You should return Http204/No Content , which tells the browser that your server has confirmed and processed your request, but it did not return anything and did not process it accordingly (no matter how you want it).

If you use jQuery (for example), it will automatically go to your success handler, and if you do not have control over it, you have done everything possible.

Read the full list of status codes here.

+3
source

Source: https://habr.com/ru/post/1299307/


All Articles