Вы можете использовать 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
}
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);
}
});