I have some variables in sort-item.js file and want to trasfer them to js in html.
Here are the details: Because of Django CSRF protection when post data, I could only put the $ajax function in html like this:
<html>
<body>...</body>
<script>
var post_data = {
"name": "saveorder",
"item_id": item_dataid,
"from": from_index,
"to": to_index,
"order": order
};
$.ajax({
type: 'POST',
data: post_data,
...
});
</script>
<html>
Meanwhile I have got this below in sort-item.js and can show the data in console log:
var itemContainers = Array.prototype.slice.call(kanban.querySelectorAll('.board'));
itemContainers.forEach(function (container) {
.on('dragReleaseEnd', function (item) {
...
var item_dataid = item.getElement().getAttribute('data-id');
console.log(item_dataid);
var order = muuri.getItems().map(item => item.getElement().getAttribute('data-id'));
console.log(order);
})
.on('move', function (data) {
var from_index = data.fromIndex;
var to_index = data.toIndex;
console.log(from_index + ' ' + to_index);
})
}
My question is how to transfer data.fromIndex, data.toIndex, order from sort-item.js to javascript variable post_data in html?