$('#assign_categories_form').on('submit', function (event) {
event.preventDefault();
var documents = [];
$.each($("#documents_auth_select option:selected"), function(){
documents.push($(this).val());
});
if (documents.length === 0) {
$('#modal_message_title').html( 'Nessun documento selezionato...' );
$('#modal_message_p').html( 'È necessario selezionare almeno un documento a cui assegnare delle categorie!' );
$('#modal_message_div').modal();
return false;
}
var categories = [];
$.each($("#dl_categories option:selected"), function(){
categories.push($(this).val());
});
if (categories.length === 0) {
$('#modal_message_title').html( 'Nessuna categoria selezionata...' );
$('#modal_message_p').html( 'È necessario selezionare almeno una categoria prima di procedere!' );
$('#modal_message_div').modal();
return false;
}
console.log(documents);
$.ajax({
type: 'POST',
url: ajax_db.ajaxurl,
contentType: 'application/json',
data: JSON.stringify({
action: 'assign_categories',
documents: documents,
categories: categories
}),
success: function (data) {
alert(data);
}
});
});
});
I need to pass documents and categories arrays to PHP with AJAX, in past I used JSON.stingify but I can't understand how to do in WordPress...
EDIT:
EDIT: I tried writing: