I'm currently facing an issue with a JavaScript event-triggered function that is supposed to send a POST request to update objects in my database. The function is triggered by a drop-event, which made me initially avoid using forms for the request. However, I am now questioning if that was the right approach.
Update:
I realized that my mistake was not including the csrf_token in my post request. Despite fixing that, I am still encountering an error: when I print(request.POST) in my Django view, the post request appears empty.
Here is a snippet of my JS file:
[JS code will go here]
The query-dict returns as empty when using 'application/json' as the Content-Type header. However, switching to 'application/x-www-form-urlencoded' resolves the issue, albeit with all the data under the same key.
For instance:
Output with 'application/json':
<QueryDict: {}>
Output with 'application/x-www-form-urlencoded':
<QueryDict: {'{"request_name":"change-extra-fields","type":"increase","id":"8"}': ['']}>
Despite this, I believe that the 'application/json' should be working and I am uncertain why it isn't functioning as expected.