I think I've run into the same problem, which is a limitation of the
default encoding used `application/x-www-form-urlencoded`. If you send
data encoded as `application/json` you will be able to send with the
expressive power of JSON, which should mean you can send nested data, or
as in your case, empty lists.
Here's a way to configure all (local) AJAX requests to do this,
using jQuery.ajaxPrefilter.
- $.ajaxPrefilter(function(options) {
-
- // Restrict this behavior to requests aimed at our own backend.
- var localOrigin = (document.location.protocol + '//' + document.location.host);
- var isLocalRequest = (
- (options.url.indexOf('://') === -1) ||
- (options.url.slice(0, localOrigin.length) === localOrigin)
- );
-
- // Restrict to requests that send data in the request body.
- var type = options.type.toLowerCase();
- var isDataRequest = (
- type === 'post' || type === 'put' || type === 'delete'
- );
-
- if (isLocalRequest && isDataRequest) {
- options.processData = false;
- options.contentType = 'application/json; charset=utf8';
- options.data = $.toJSON(options.data);
- }
-
- });
If you run this once, all future requests will be encoded as JSON.
Hopefully this works, because I trimmed from a more sophisticated
version. But you can get the basic idea.
Also you might need to configure your backend to accept and decode
the JSON data, I use django-rest-framework which fortunately made this
very easy.