Я не могу отправить php по URL [закрыто]Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Я не могу отправить php по URL [закрыто]

Сообщение Anonymous »

Код: Выделить всё

public function toggle_checklist_notes(): void
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$notes = $data['notes'] ?? [];

foreach ($notes as $noteId) {
$note = ChecklistNote::get_by_id($noteId);
if ($note) {
foreach ($note->get_items() as $item) {
$item->toggle_checkbox();
}
}
}

// Get the user ID from the request (or session, as needed)
$user_id = isset($data['user_id']) ? (int)$data['user_id'] : null;

if ($user_id) {
$user = User::get_user_by_id($user_id);
if ($user) {
$updatedNotes = $user->get_checklist_notes();
$responseNotes = array_map(function($note) {
return [
'id' => $note->get_id(),
'title' => $note->get_title(),
'checked_count' => $note->get_checked_count(),
'total_count' => $note->get_total_count(),
];
}, $updatedNotes);

header('Content-Type: application/json');
echo json_encode(['notes' => $responseNotes]);
exit;
}
}

header('Content-Type: application/json');
echo json_encode(['notes' => []]);
exit;
}
}

Код: Выделить всё

document.addEventListener('DOMContentLoaded', function() {
const noteCheckboxes = document.querySelectorAll('.note-checkbox');
const toggleButton = document.getElementById('toggle-check-button');
const selectedUserId = document.querySelector('select\[name="selected_user"\]').value;

noteCheckboxes.forEach(checkbox =\> {
checkbox.addEventListener('change', function() {
toggleButton.disabled = !document.querySelectorAll('.note-checkbox:checked').length;
});
});

toggleButton.addEventListener('click', function() {
const selectedNotes = Array.from(document.querySelectorAll('.note-checkbox:checked')).map(checkbox =\> checkbox.value);

fetch('session1/toggle_checklist_notes', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ notes: selectedNotes, user_id: selectedUserId })
})
.then(response =\> response.json())
.then(response =\> {
updateChecklist(response.notes);
})
.catch(error =\> {
console.error('Error:', error);
});
});
});

function updateChecklist(notes) {
const notesList = document.getElementById('notes-list');
notesList.innerHTML = '';
notes.forEach(note =\> {
const li = document.createElement('li');
li.innerHTML = \`
${note.title} (${note.checked_count}/${note.total_count} checked)\`;
notesList.appendChild(li);
});

}
Я не могу опубликовать значения для скрипта. Я пробовал несколько методов, но в URL-адресе ничего нет. Это php и javascript, вам нужно сделать это одним методом, спасибо за ваша помощь, у меня нет подробностей, я занимаюсь этим уже 1 неделю, как интегрировать значение в заголовок

Подробнее здесь: https://stackoverflow.com/questions/786 ... php-in-url
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»