Не могу передать массив в Django REST

Вы можете использовать Regex:

if (str.replace(/[\s\n\r]+/g, "") != "")
{
    // if you remove spaces and line breaks, it doesn't equal nothing
}

EDIT - он должен быть быстрее

if (/\S/.test(str))
{
    // found something other than spaces or line breaks

    // "\S" should match any character that is not a space or line break
}
0
задан jeremysprofile 25 June 2019 в 23:01
поделиться

1 ответ

var authors = [];
authors[0] = 1;
authors[1] = 2;

var arr = {
    "csrfmiddlewaretoken": getCookie('csrftoken'),
    "title": "dasf",
    "desct": "dasf",
    "content": "fdasf",
    "authors": authors
    };

$.ajax({
    url: '/api/save-post/',
    type: 'POST',
    data: arr,
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {
        alert(msg);
    }
});
0
ответ дан ParthS007 25 June 2019 в 23:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: